mysql学习之-密码管理(默认密码,修改密码,解决忘记密码)
2016-12-14 22:35
531 查看
1. mysql安装后默认没有密码,初始化安装后默认密码登录,需要马上修改root密码。
[root@mysql ~]# cat /root/.mysql_secret --查看root账号密码
# The random password set for the root user at Tue Dec 13 18:59:06 2016 (local time): 7MhtyX3aZEl9OUf8
[root@mysql ~]# mysql -uroot -p -- 登录mysql
Enter password: --(此处复制粘贴 7MhtyX3aZEl9OUf8)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.25
Copyright (c) 2000, 2015, 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> 表示一切顺利成功。
2. 修改密码
mysql> SET PASSWORD = PASSWORD('123456'); --设置密码为123456
[root@mysql etc]# mysql -uroot -p123456 --修改密码后,登录
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 5.6.25 MySQL Community Server (GPL)
mysql> --登录成功
3. 忘记mysql数据库root的密码后,如何修改密码。
[root@mysql etc]# service mysql stop --停止mysql进程
Shutting down MySQL.... SUCCESS!
[root@mysql etc]# mysqld_safe --skip-grant-tables& --启动mysql时不启动grant-tables,授权表。执行后出现下面画面,另起一个新会话。
[1] 3574
[root@mysql etc]# 161215 06:13:53 mysqld_safe Logging to '/var/lib/mysql/mysql.err'.
161215 06:13:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@mysql ~]# ps -ef|grep mysql --查看mysql进程是否起来
root 3467 3440 0 05:29 pts/2 00:00:00 mysql -uandy -px xx
root 3574 2845 0 06:13 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 3677 3574 2 06:13 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-
mysql> UPDATE user SET password=PASSWORD('cccccc') WHERE user='root'; --更改root密码
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> FLUSH PRIVILEGES; --权限更新
Query OK, 0 rows affected (0.00 sec)
[root@mysql ~]# mysql -uroot -p123456 --使用旧密码登录,发现不行,说明密码已经更新
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@mysql ~]# mysql -uroot -pcccccc --新密码登录成功
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql>
[root@mysql ~]# cat /root/.mysql_secret --查看root账号密码
# The random password set for the root user at Tue Dec 13 18:59:06 2016 (local time): 7MhtyX3aZEl9OUf8
[root@mysql ~]# mysql -uroot -p -- 登录mysql
Enter password: --(此处复制粘贴 7MhtyX3aZEl9OUf8)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.25
Copyright (c) 2000, 2015, 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> 表示一切顺利成功。
2. 修改密码
mysql> SET PASSWORD = PASSWORD('123456'); --设置密码为123456
[root@mysql etc]# mysql -uroot -p123456 --修改密码后,登录
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 5.6.25 MySQL Community Server (GPL)
mysql> --登录成功
3. 忘记mysql数据库root的密码后,如何修改密码。
[root@mysql etc]# service mysql stop --停止mysql进程
Shutting down MySQL.... SUCCESS!
[root@mysql etc]# mysqld_safe --skip-grant-tables& --启动mysql时不启动grant-tables,授权表。执行后出现下面画面,另起一个新会话。
[1] 3574
[root@mysql etc]# 161215 06:13:53 mysqld_safe Logging to '/var/lib/mysql/mysql.err'.
161215 06:13:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@mysql ~]# ps -ef|grep mysql --查看mysql进程是否起来
root 3467 3440 0 05:29 pts/2 00:00:00 mysql -uandy -px xx
root 3574 2845 0 06:13 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 3677 3574 2 06:13 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-
mysql> UPDATE user SET password=PASSWORD('cccccc') WHERE user='root'; --更改root密码
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> FLUSH PRIVILEGES; --权限更新
Query OK, 0 rows affected (0.00 sec)
[root@mysql ~]# mysql -uroot -p123456 --使用旧密码登录,发现不行,说明密码已经更新
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@mysql ~]# mysql -uroot -pcccccc --新密码登录成功
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql>
相关文章推荐
- mysql学习之-密码管理(默认密码,修改密码,解决忘记密码)
- Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
- 老是忘记,这次不能忘记了。WAMP中如何修改mysql默认空密码
- mysql密码忘记或修改密码的解决办法
- Mysql 忘记root密码 修改root密码 解决方法
- mysql 解决mysql密码忘记问题,修改密码之后登录不成功的问题
- mysql修改用户密码的方法和mysql忘记密码的解决方法
- 6.(Mysql数据管理相关)连接MYSQL,修改密码,增加新用户,数据库相关命令,表操作相关命令,数据相关命令,数据库sql导入和导出,备份数据库,查看不到mysql数据库的解决办法
- mysql默认密码忘记,如何修改初始密码
- MySQL,如何修改root帐户密码、如何解决root帐户忘记密码的问题
- Linux下使用MySQL——忘记root密码及修改MySQL默认编码
- Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
- mysql 修改密码忘记使用password函数导致后面无法连接,解决方法记录
- linux下mysql的root修改密码忘记解决方法
- Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
- mysql密码忘记或修改密码的解决办法
- mysql修改密码的三方法和忘记root密码的解决方法
- mysql修改用户密码的方法和mysql忘记密码的解决方法
- mysql修改密码的三方法和忘记root密码的解决方法
- Mysql-linux下密码修改,忘记密码修改,超级管理用户修改