MySQL遇到的小问题
来源:互联网 发布:4g逛淘宝费流量么 编辑:程序博客网 时间:2024/05/01 07:36
这篇博客,如同linux上遇到的小问题一样,一直更新,把平时项目中遇到的MySQL问题及解决方法都贴在这,以供自己以后查看。
1、项目中有的表字段用到了枚举型(enum),如“`is_show` enum('0','1') NOT NULL COMMENT '是否显示 0否 1是'”,这时要查询表中显示的记录,一开始是这么写的,“SELECT * FROM tablename WHERE is_show = 1”,可实际得到的数据却是未显示的,仔细查看了下建表语句,发现应该要加上引号,否则会被认为是0的,“SELECT * FROM tablename WHERE is_show = "1"”。
2、以root身份进入mysql内,没有发现mysql库,可能是权限没有了,退出去,关掉mysql进程,以“/www/mysql/bin/mysqld -uroot --skip-grant-tables”方式启动
service mysqld stop/www/mysql/bin/mysqld -uroot --skip-grant-tablesmysqluse mysql;update user set Select_priv ='Y' where user = 'root';update user set Insert_priv ='Y' where user = 'root';update user set Update_priv ='Y' where user = 'root';update user set Delete_priv ='Y' where user = 'root';update user set Create_priv ='Y' where user = 'root';update user set Drop_priv ='Y' where user = 'root';update user set Reload_priv ='Y' where user = 'root';update user set Shutdown_priv ='Y' where user = 'root';update user set Process_priv ='Y' where user = 'root';update user set File_priv ='Y' where user = 'root';update user set Grant_priv ='Y' where user = 'root';update user set References_priv ='Y' where user = 'root';update user set Index_priv ='Y' where user = 'root';update user set Alter_priv ='Y' where user = 'root';update user set Show_db_priv ='Y' where user = 'root';update user set Super_priv ='Y' where user = 'root';update user set Create_tmp_table_priv ='Y' where user = 'root';update user set Lock_tables_priv ='Y' where user = 'root';update user set Execute_priv ='Y' where user = 'root';update user set Repl_slave_priv ='Y' where user = 'root';update user set Repl_client_priv ='Y' where user = 'root';update user set Create_view_priv ='Y' where user = 'root';update user set Show_view_priv ='Y' where user = 'root';update user set Create_routine_priv ='Y' where user = 'root';update user set Alter_routine_priv ='Y' where user = 'root';update user set Create_user_priv ='Y' where user = 'root';update user set Event_priv ='Y' where user = 'root';update user set Trigger_priv ='Y' where user = 'root';update user set Create_tablespace_priv ='Y' where user = 'root';flush privileges;exit;#停止刚刚那个mysqld进程,再重启mysqlps aux | grep mysqldkill 进程service mysqld start
3、重装mysql前,一定得备份下数据表,mysiam引擎的好说,innodb的除了备份库名字的目录外,还的备份ibdata文件,因为innodb引擎表的数据和索引存在ibdata内。
4、导入sql文件时,报“Got a packet bigger than 'max_allowed_packet' bytes”,在my.cnf中的[MySQLd]下面加上max_allowed_packet=10M,这个值大于导入的文件即可,重启MySQL。
5、接着第四条,进入MySQL,use sugarcrm,之后提示“Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A”,因为导入的数据很大,有2G多,这个库也很大,表也很多。在use 该库时,MySQL需要预读数据库信息,由于量大,于是出现提示,只需要在进入MySQL时,加上个-A参数即可,“mysql -uroot -ppassword -A”。
6、如果本地或是服务器导入sql文件时,经常这两种错误,‘Lost connection to MySQL server during query’、‘Got a packet bigger than 'max_allowed_packet' bytes’,那么需要在配置文件中重新设置max_allowed_packet。
7、select ... into outfile ...方式导出数据,只能在连接的MySQL服务器上导出,没有加路径,则为/var/lib/mysql/当前数据库文件目录,加了目录则在/tmp目录里,若是在其他服务器远程连接,则会报“ERROR 1 (HY000) at line 1: Can't create/write to file ”错误。
8、MySQL 5.6 去掉严格模式
vim /etc/my.cnfsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES sql_mode=NO_ENGINE_SUBSTITUTION
9、启动MySQL时报“Starting MySQL.. ERROR! The server quit without updating PID file (/www/mysql/data/FJR-bt-kvm-72-26.pid)”
/www/mysql/data/FJR-bt-kvm-72-26.pid没有权限chmod 777 /www/mysql/data/FJR-bt-kvm-72-26.pid#如果解决不了,可以移步看看这个 http://blog.rekfan.com/articles/186.html
10、进入mysql库后,grant 操作报“ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)”
update user set Create_tablespace_priv ='Y' where user = 'root';flush privileges;
11、删除原有主键,重新设置主键
1、取消主键alter table `table_name` drop primary key;2、添加a_idalter table `table_name` add column `a_id` int(11) unsigned not null first; 3、添加主键ALTER TABLE `table_name` MODIFY COLUMN `a_id` INT(11) NOT NULL AUTO_INCREMENT, add PRIMARY KEY (`a_id`);
- MySQL遇到的小问题
- myeclipse连接mysql遇到的小问题
- mysql相关 timestamp遇到的小问题
- mysql 存储过程遇到的小问题
- 初探Mysql遇到的小问题
- 遇到的小问题
- 遇到的小问题
- 遇到的小问题
- 遇到的小问题
- 遇到的小问题
- mysql遇到的一些常用的查询小问题
- mysql mybaits批量更新时遇到的一个小问题
- mysql与oracle转换遇到小问题 关键字的处理
- 在Linux下使用MySQl遇到的小问题集合
- javaee-mysql-jdbc中遇到的小问题一
- MySQL数据库连接过程中遇到的小问题
- mybatis+mysql小批量插入语法以及遇到的问题
- 记MyBatis和MySQL中遇到的一些小问题
- 甘肃康婷网络直销好做吗?赚钱吗?
- Oracle SET UNUSED的用法
- 红包抢不到怎么办?——CSDN感恩回馈,C币充值巨优惠!
- oracle怎样卸载干净(不用在重做系统了)
- Qt 3D的研究(三):显示3D模型
- MySQL遇到的小问题
- UITextfiel 网上找的比较全面的资料
- 栈的一些简单操作
- Android Service 的几个用途
- sqlite分页查询
- 十六进制转换成十进制
- Runnable和Thread实现多线程的区别(含代码)
- 基于mini5350的WIFI视频小车
- 各种神注释