mysql的常见问题和操作

今天发现搭在环境上的mysql数据库被黑,数据库直接被干掉了,只能重新恢复数据库运行,不指望能要回数据了,恢复过程中遇到一些问题,只是做简单记录:
1.mysql的启停:
启动:service mysqld start
重启:service mysqld restart
停止:service mysqld stop
2.重启过程中发现后台报错:
  2.1 启动之前打开mysql运行监控日志: tail -f /var/log/mysqld.log
  2.2 运行service mysqld restart报错:
      [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
      解决过程:
      网上有人运行: mysql_install_db –usrer=mysql datadir=/var/lib/mysql
      PS:datadir是mysql存放文件目录;
      这个操作我试过,效果跟网上那个帖子说的一样,是不行的;
      然后继续使用他后面提到的命令:mysql_install_db,意思是重新初始化了一把数据库,
      这时再重启数据库,终于成功了
      帖子参考地址http://blog.csdn.net/indexman/article/details/16980433
3.修改登陆密码:
  # mysql -uroot -p
  Enter password: 【输入原来的密码】
  mysql>use mysql;
  mysql> update user set password=passworD("test1314") where user='root';
  mysql> flush privileges;
  mysql> exit;  
4.客户端远程连接数据库:
  客户端报错:Host "10.13.23.12" is not allowed connect to this mysql sercer
  解决过程:
  修改服务端mysql root用户的监听ip为通配:
   # mysql -uroot -p
    mysql>use mysql;
    mysql>use mysql;
    mysql> update user set host='%' where user='root' and host='localhost';

5.选择数据库报错:
# mysql -uroot -p
mysql> use mysql
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
这个是由于user表有user用户为空的记录导致无法选择mysql用户登陆数据库
解决过程:
1>:# service mysqld stop
Stopping mysqld:                                           [  OK  ]
[root@VM_16_12_centos ~]# /usr/bin/mysqld_safe --skip-grant-tables
171226 20:11:06 mysqld_safe Logging to '/var/log/mysqld.log'.
171226 20:11:07 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2>:新启一个ssh窗口:
    # mysql -uroot -p
    mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user;
+--------------------+------+
| host               | user |
+--------------------+------+
| %                  | root |
| 127.0.0.1          | root |
| localhost          |      |
| vm\_16\_12\_centos |      |
| vm\_16\_12\_centos | root |
+--------------------+------+
5 rows in set (0.00 sec)

mysql> delete from user where user='';
Query OK, 2 rows affected (0.00 sec)

mysql> select host,user from user;
+--------------------+------+
| host               | user |
+--------------------+------+
| %                  | root |
| 127.0.0.1          | root |
| vm\_16\_12\_centos | root |
+--------------------+------+
3 rows in set (0.00 sec)
# service mysqld start
# mysql -uroot -p
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
这样就好了。
没怎么注意博客样式,只是记录下问题的解决过程,供自己以后看的,大家如果有什么问题,还是多百度吧,解决问题的优秀的帖子很多,大家还是要有耐心好好看看。






      
     

猜你喜欢

转载自jifeng305.iteye.com/blog/2405847