Mysql安装后,会自动给root用户生成一个默认密码,一般安装过程中会有提示,但如果安装过程中没注意,那安装后就没法用root登录了。

其它找到默认密码的命令很简单,一个命令就搞定:

1
cat /root/.mysql_secret

如果是其它用户安装的,需要把/root替换成其它用户的home目录,比如oper用户,默认的home目录就是/home/oper/

增加了密码后的登录格式如下:

1
2
mysql -u root -p 
Enter password: (输入密码) 

其中-u后跟的是用户名,-p要求输入密码,回车后在输入密码处输入密码。

MySQL安装解决方法:重改密码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# /etc/init.d/mysqld stop 
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
# mysql -u root mysql 
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# /etc/init.d/mysqld restart 
# mysql -uroot -p 
Enter password: 
mysql>搞定!

查看MYSQL数据库中所有用户

1
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;