忘记MySQL超户密码的解决方法 * MySQL数据库超户root 与centos超户root不是一个用户
登录数据库时出现以下提示时:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
意思是 预读这个库中表以及表列信息,一般原因是当库中表很多,表中数据很大时,就会出现执行use <库名>后半天没反应,连接很慢的情况,解决办法就是 -A 方式登录数据库,不会预读库中表信息。
解决办法:[root@ns1 ~]# mysql -uroot -p -A
1】先暂停mysql服务
[root@ns1 ~]# /etc/init.d/mysqld stop
Shutting down MySQL. [确定]
2】跳过grant表授权,计入安全模式,并在后台运行。
[root@ns1 ~]# mysqld_safe --skip-grant-tables & //skip(跳过)grant(授权)&后台
[root@ns1 ~]# jobs //查询后台运行程序
- + Running mysqld_safe --skip-grant-tables &
3】进入安全模式修改密码
[root@ns1 ~]# mysql //登录数据库
...............................
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql; //进入MySQL数据库
Database changed
mysql> update user set Password=password('123321') where user='root';
//update(修改数据)set(查看)password('123321') 调取函数必须添加() where(查询定位用户)
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges; // flush(刷新) privileges(权限)
Query OK, 0 rows affected (0.00 sec)
4】重启MySQL服务用新密码登录。
[root@ns1 ~]# /etc/init.d/mysqld restart //重启MySQL服务
Shutting down MySQL.190509 06:20:15 mysqld_safe mysqld from pid file /usr/local/mysql/data/ns1.kgc.cn.pid ended
[确定]
Starting MySQL.. [确定]
- + Done mysqld_safe --skip-grant-tables
[root@ns1 ~]# mysql -uroot -p123321 //新密码登录
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
...................................
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
如何在MySQL数据库中开启使用tab键补全命令功能
1】修改配置文件/etc/my.cnf
vim /etc/my.cnf
132 [mysql]
133 #no-auto-rehash