阿里云CentOS服务器中MySQL数据库的默认密码及修改

服务器信息

系统镜像:CentOS 7.3

阿里云CentOS服务器中MySQL数据库的默认密码及修改_第1张图片

应用镜像:LAMP(Linux + Apache + MySQL + PHP),即mysql默认是安装好的。

阿里云CentOS服务器中MySQL数据库的默认密码及修改_第2张图片

命令

[root@deb ~]# # 登入系统,查看env.txt
[root@deb ~]# pwd
/root
[root@deb ~]# ls
env.txt  sa_recovery.log
[root@deb ~]# cat env.txt
mysql_root_passwd:mysql的初始密码串
webroot_dir:/home/www/htdocs
apache_dir:/usr/local/apache
mysql_dir:/usr/local/mysql
php_dir:/usr/local/php56

[root@deb ~]# # 启动mysqld服务器
[root@deb ~]# /etc/rc.d/init.d/mysqld status
MySQL is not running                                       [FAILED]
[root@deb ~]# /etc/rc.d/init.d/mysqld start
Starting MySQL.                                            [  OK  ]

[root@deb /]# # 登录mysql会话。
[root@deb /]# cd /usr/local/mysql/bin
[root@deb bin]# ./mysql -uroot -pmysql的初始密码串
mysql: [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 5
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> # 查看mysql.user表中的账号信息
mysql> select Host, User, plugin, authentication_string, password_expired, password_last_changed, account_locked from mysql.user \G
*************************** 1. row ***************************
                 Host: localhost
                 User: root
               plugin: mysql_native_password
authentication_string: *这里是一串用于认证的经过加密的字符串
     password_expired: N
password_last_changed: 2018-11-02 23:03:05
       account_locked: N
*************************** 2. row ***************************
                 Host: localhost
                 User: mysql.sys
               plugin: mysql_native_password
authentication_string: *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE
     password_expired: N
password_last_changed: 2017-08-08 12:07:24
       account_locked: Y
2 rows in set (0.00 sec)

mysql> # 如果二者相同则结果为1;若不相同则返回0.
mysql> select (1 = 1), ('aa' = 'ab');
+---------+---------------+
| (1 = 1) | ('aa' = 'ab') |
+---------+---------------+
|       1 |             0 |
+---------+---------------+
1 row in set (0.00 sec)

mysql> # 证明:mysql中账户密码使用了password(str)对密码进行加密处理。
mysql> select password('mysql的初始密码串') = (select authentication_string from mysql.user where User = 'root');
+-----------------------------------------------------------------------------------------------+
| password('mysql的初始密码串') = (select authentication_string from mysql.user where User = 'root') |
+-----------------------------------------------------------------------------------------------+
|                                                                                             1 |
+-----------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> # 修改密码(多种方法,不同工具|版本,操作也有细微的差别)
mysql> set password for 'root'@'localhost' = password('toor');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql>exit
Bye

你可能感兴趣的:(Linux)