mysql平日工作总结
1.mysql 远程连接,首先要让设置连接权限,也就是本地mysql有权限连接远程mysql
/usr/local/mysql/bin/mysql -h$ip_database -uhqtroot -p$dbpasswd $dbname -e ""
2.replace使用方法
比如你要将 表 table1 里面的 filed字段的abc替换为def
UPDATE table1 SET field1=REPLACE(field1, 'abc', 'def');
如果多条命令可以写成如下形式(用续行符\):
$remotemysql -e " update reviews_description set reviews_text=replace(reviews_text,'paypal','Credit Card')\
,reviews_text=replace(reviews_text,'Paypal','Credit Card')\
,reply_text=replace(reply_text,'PAYPAL','Credit Card');"
3.Mysql报错需修复
weddingshopcaloundra_com.whos_online
REPAIR TABLE whos_online
4.mysql删除符合条件记录,例如:删除pages_id255-232记录
delete from ezpages where pages_id>=225 and pages_id<=232;
6.如果mysql查询字段中有单引号,查询时把单引号换成双引号如下:
如搜索:Men's Jewelry
select * from categories where categories_name=’Men's Jewelry’ 这样会报错改成如下形式
select * from categories where categories_name=’Men''s Jewelry’
7.mysql中左联与右联例子:
select b.products_model,b.products_image from products_to_categories a left join products b on a.products_id=b.products_id where a.categories_id='$cate_id' and b.products_status='1'
8. mysql regexp 扩展正则表达式 使用
例子:更新products 表,把product_is_always_free_shipping的值设为0也就是不免费,条件是products_model开头为001到006的记录
update products set product_is_always_free_shipping='0' where products_model regexp \"^00[1-6]-\";
9. mysql报错,说明有分区已经满
1030 Got error 28 from storage engine
10. mysql用户设置密码及权限
SET PASSWORD FOR root@'localhost' = PASSWORD('abcdef');
grant all on *.* to hqtroot@'127.0.0.1' identified by 'abcdef';
grant all on *.* to hqtroot@'174.36.9.%' identified by 'abcdef;
flush privileges;
11. Distinct找不重复的记录
select distinct products_options_id from products_options where products_options_name='Size';
12.按条件升序降序排列
select products_id from products where products_status=1 order by products_id desc limit 1;
asc 按升序排列 desc 按降序排列
13查看mysql表结构的方法有三种:
1、desc tablename;
2、show create table tablename;
3、use information_schema;select * from columns where table_name='tablename'
14.mysql报错解决办法
52hqt:/usr/local/src/mysql-5.1.57# /usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/data/db/
FATAL ERROR: Could not find mysqld
The following directories were searched:
/usr/libexec
/usr/sbin
/usr/bin
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
运行下面命令
/usr/local/src/mysql-5.1.57# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql
14. SHOW STATUS;
解释:显示一些系统特定资源的信息,例如,正在运行的线程数量
15. SHOW PROCESSLIST;
解释:显示系统中正在运行的所有进程,也就是当前正在执行的查询。大多数用户可以查看他们自己的进程,但是如果他们拥有PROCESS权限,就可以查看所有人的进程,包括密码
SHOW TABLE STATUS;
解释:显示当前使用或者指定的DATABASE中的每个表的信息。信息包括表类型和表的最新更新时间
17. MySQl 追加内容到原字段
文本内容追加:
update 表名 set 字段名=concat(字段名,”追加文本”) where 字段=条件
数据计算追加:
update 表名 set 字段名= 字段名 + 追加数据 where 字段=条件
sql文件追加
update 表名 set 字段名=concat(字段名,”source sql.txt”) where 字段=条件