1.如果忘记了mysql的root密码,可以用以下方法解决
1)先关闭msyql,用如下方法启动msyql
[root@tvmyunying ~]#service mysqld stop [root@tvmyunying ~]# /usr/bin/mysqld_safe --skip-grant-tables &
--skip-grant-tables 不使用任何数据库信息去访问
2)更新root用户密码
[root@tvmyunying ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.61 Source distribution Copyright (c) 2000, 2011, 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> 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 mysql> update user set password=password("12345678") where user="root"; Query OK, 3 rows affected (0.02 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
3)重启数据库
[root@tvmyunying ~]#service mysqld restart
2.MySQL5.6初始化时修改mysql数据密码
mysql> set password for root@localhost=password('redhat'); Query OK, 0 rows affected (0.00 sec)
本文出自 “eagle” 博客,转载请与作者联系!