最后重启一下mysql服务service mysqld restart
http://xm.cmgine.net/archives/9569.html
mysqldump备份出现Table 'user_suggest_report' doesn't exist when using LOCK TABLES
执行mysqldump 时出现找不到某一个 tables 并且中断执行
[root@test100 data]# mysqldump fx > fx.sql
mysqldump: Got error: 1146: Table 'user_suggest_report' doesn't exist when using LOCK TABLES
考虑加上 --skip-lock-tables或者-R进行锁表试试,也是不行.
[root@test100 data]#mysqldump --skip-lock-tables fx > fx.sql
Error: Couldn't read status information for table vote_results () mysqldump: Couldn't execute 'show create table `user_suggest_report`': Table 'fx.user_suggest_report' doesn't exist (1146)
登陆服务器查看是否存在此表
[root@test100 data]#mysql -h127.0.0.1 -D fx
mysql> show tables;
+--------------------------------+
| Tables_in_fx |
+--------------------------------+
| user_suggest_report |
+--------------------------------+
删除此表
mysql> drop table user_suggest_report; #既然存在的,但系统认定不存在说明有问题,索性删除
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user_suggest_report' at line 1
进入mysql存储目录下将其数据表移动或删除
[root@test100 data]# cat /etc/my.cnf | grep datadir
datadir=/var/lib/mysql
[root@test100 data]# cd /var/lib/mysql/fx/
[root@test100 fx]# mv user_suggest_report.frm /data
重启mysql服务器
[root@test100 fx]# service mysqld restart
重新备份操作
[root@test100 data]# mysqldump fx > fx.150109.sql #操作成功 MySQL 5.5 mysqldump工作过程中遇到的问题
场景1
系统版本:CentOS 6.4MySQL版本:5.5.35-log Source distribution逻辑备份命令:mysqldump还原数据命令:source 备份文件
[root@localhost ~]# ll -d /tmp/cloudTest.sql -rw-r--r-- 1 root root 1575809806 2月 28 09:04 /tmp/cloudTest.sql 问题:备份文件cloudTest,sql是二进制安装MySQL5.5下的备份文件,然后导入到源码编译MySQL5.5环境下中遇到的导入错误,重复导入几次,依然报错如下:
恢复现场:
[root@localhost ~]# mysql
Your MySQL connection id is 3
Server version: 5.5.35-log Source distribution
mysql> create database cloudTest;
mysql> user cloudTest;
mysql> set session sql_log_bin = 0
mysql> source /tmp/cloudTest.sql;
......(执行时长25分钟左右)
ERROR 1231 (42000): Variable 'time_zone' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'foreign_key_checks' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'unique_checks' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'character_set_client' can't be set to the value of 'NULL'
Query OK, 0 rows affected (0.00 sec)
ERROR 1231 (42000): Variable 'collation_connection' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'sql_notes' can't be set to the value of 'NULL'
解决办法:
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
max_allowed_packet = 500M
[mysqldump]
quick
max_allowed_packet = 500M
[root@localhost ~]# service mysqld restart
再次执行恢复现场操作
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.35-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySql innodb如果是共享表空间,ibdata1文件越来越大,达到了30多个G,对一些没用的表进行清空:
truncate table xxx;
然后optimize table xxx; 没有效果
因为对共享表空间不起作用。
mysql ibdata1存放数据,索引等,是MYSQL的最主要的数据。
如果不把数据分开存放的话,这个文件的大小很容易就上几十G。对于某些应用来说,并不是太合适。因此要把此文件缩小。
无法自动收缩,必须数据导出,删除ibdata1,然后数据导入,比较麻烦,因此需要改为每个表单独的文件。
解决方法:数据文件单独存放(共享表空间如何改为每个表独立的表空间文件)。
1)备份数据库
备份全部数据库,执行命令
#mysqldump -q -uroot -ppassword --add-drop-table --all-databases >/home/backup/all.sql
做完此步后,停止数据库服务。
#service mysqld stop
2)找到my.ini或my.cnf文件
linux下执行
# /usr/libexec/mysqld --verbose --help | grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
windows环境下可以:
mysqld --verbose --help > mysqlhelp.txt
notepad mysqlhelp.txt
在里面查找Default options,可以看到查找my.ini的顺序,以找到真实目录
3)修改mysql配置文件
打开my.ini或my.cnf文件
[mysqld]下增加下面配置
innodb_file_per_table=1
验证配置是否生效,可以重启mysql后,执行
#service mysqld restart
#mysql -uroot -ppassword
mysql> show variables like '%per_table%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
1 row in set (0.00 sec)
看看innodb_file_per_table变量是否为ON
4)删除原数据文件
删除原来的ibdata1文件及日志文件ib_logfile*,删除/var/lib/mysql目录下的应用数据库文件夹(mysql文件夹不要删)
5)还原数据库
启动数据库服务,还原全部数据库,执行命令
#service mysqld start
#mysql -uroot -pocs < /home/backup/all.sql
经过以上几步后,可以看到新的ibdata1文件就只有几十M了,数据及索引都变成了针对单个表的小ibd文件了,它们在相应数据库的文件夹下面。
# ll
drwx------ 2 mysql mysql 36864 Apr 22 14:16 glpi
drwx------ 2 mysql mysql 36864 Feb 15 13:45 glpi-1
-rw-rw---- 1 mysql mysql 10485760 Apr 22 14:27 ibdata1
-rw-rw----. 1 mysql mysql 270532608 Apr 22 14:14 ibdata1-1
-rw-rw---- 1 mysql mysql 5242880 Apr 22 14:27 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 Apr 22 14:14 ib_logfile0_bak
-rw-rw---- 1 mysql mysql 5242880 Apr 22 14:28 ib_logfile1
-rw-rw----. 1 mysql mysql 5242880 Apr 21 22:50 ib_logfile1_bak
drwx------ 2 mysql mysql 4096 Apr 22 14:16 mrbs
drwx------ 2 mysql mysql 4096 Apr 14 12:05 mrbs-1
drwx------. 2 mysql mysql 4096 Apr 22 14:16 mysql
srwxrwxrwx 1 mysql mysql 0 Apr 22 14:16 mysql.sock
drwx------ 2 mysql mysql 12288 Apr 22 14:16 ocsweb
drwx------ 2 mysql mysql 12288 Nov 16 2011 ocsweb-1
# ll mrbs
total 808
-rw-rw---- 1 mysql mysql 61 Apr 22 14:16 db.opt
-rw-rw---- 1 mysql mysql 10492 Apr 22 14:16 mrbs_area.frm
-rw-rw---- 1 mysql mysql 98304 Apr 22 14:16 mrbs_area.ibd
-rw-rw---- 1 mysql mysql 9264 Apr 22 14:16 mrbs_entry.frm
-rw-rw---- 1 mysql mysql 131072 Apr 22 14:16 mrbs_entry.ibd
-rw-rw---- 1 mysql mysql 9442 Apr 22 14:16 mrbs_repeat.frm
-rw-rw---- 1 mysql mysql 98304 Apr 22 14:16 mrbs_repeat.ibd
-rw-rw---- 1 mysql mysql 8888 Apr 22 14:16 mrbs_room.frm
-rw-rw---- 1 mysql mysql 114688 Apr 22 14:16 mrbs_room.ibd
-rw-rw---- 1 mysql mysql 8688 Apr 22 14:16 mrbs_users.frm
-rw-rw---- 1 mysql mysql 98304 Apr 22 14:16 mrbs_users.ibd
-rw-rw---- 1 mysql mysql 8658 Apr 22 14:16 mrbs_variables.frm
-rw-rw---- 1 mysql mysql 98304 Apr 22 14:16 mrbs_variables.ibd
-rw-rw---- 1 mysql mysql 8738 Apr 22 14:16 mrbs_zoneinfo.frm
-rw-rw---- 1 mysql mysql 98304 Apr 22 14:16 mrbs_zoneinfo.ibd
# ll mrbs-1
total 88
-rw-rw---- 1 mysql mysql 61 Apr 14 12:05 db.opt
-rw-rw---- 1 mysql mysql 10492 Apr 14 12:05 mrbs_area.frm
-rw-rw---- 1 mysql mysql 9264 Apr 14 12:05 mrbs_entry.frm
-rw-rw---- 1 mysql mysql 9442 Apr 14 12:05 mrbs_repeat.frm
-rw-rw---- 1 mysql mysql 8888 Apr 14 12:05 mrbs_room.frm
-rw-rw---- 1 mysql mysql 8688 Apr 14 12:05 mrbs_users.frm
-rw-rw---- 1 mysql mysql 8658 Apr 14 12:05 mrbs_variables.frm
-rw-rw---- 1 mysql mysql 8738 Apr 14 12:05 mrbs_zoneinfo.frm mysql 5.7.9 [Err] 1055 插入时候会报sql_mode=only_full_group_by
mysql 5.7.9 [Err] 1055 插入时候会报下面错误:
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause
and contains nonaggregated column 'information_schema.PROFILING.SEQ'
which is not functionally dependent on columns in GROUP BY clause; this
is incompatible with sql_mode=only_full_group_by
进行数据库查看如下:
MySQL错误:ERROR 1175: You are using safe update mode 解决方法
操作MySQL数据库,删除表中的某一行数据提示如下错误:
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column 错误提示:正在使用安全更新模式,尝试更新表没有使用键列的where条件;
原因是:mysql有个叫SQL_SAFE_UPDATES的变量,为了数据库更新操作的安全性,此值默认为1,所以才会出现更新失败的情况。
mysql> show variables like 'sql_safe%';
+------------------+-------+
mysql误删除root帐号处理方法
方法一:
第一步:
mysqld_safe --skip-grant-tables --skip-networking & (跳过密码启动)
第二步:增加root表
insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
第三步:root赋予权限
update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y',> 第四步:退出,重新登入
方法二:
到其他服务器的mysql data路径下,复制user.frm,user.MYD,user.MYI 到当前问题服务器路径下,然后重启mysql 即可。
防止人为误操作MySQL数据库技巧一例
背景:DBA人员登录数据库update一个记录,结果忘了加where,于是导致所有数据发生了改变。
技巧如下: 1、mysql帮助说明
# mysql --help|grep dummy
-U, --i-am-a-dummy Synonym for option --safe-updates, -U.
i-am-a-dummy FALSE 2、指定-U登录测试,提示:不加条件无法删除,目的达到。
# mysql -uroot -p123456 -S /var/lib/mysql/mysql.sock -U
mysql> delete from oldboy.student;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
mysql> quit 3、做成别名防止老大和DBA误操作
# alias mysql='mysql -U'
# mysql -uroot -p123456 -S /data/3306/mysql.sock
mysql> delete from oldboy.student;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
mysql> delete from oldboy.student where Sno=5;
方法一:
# echo "alias mysql='mysql -U'" >>/etc/profile
# source /etc/profile
# tail -1 /etc/profile
alias mysql='mysql -U'
方法二:
在my.cnf里面把safe-updates的注释取消,达到同样效果。
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL