系統爲centos7,安裝的mysql5.7版本
#獲取repo
[root@slave1 home]# wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
#安裝repo
[root@slave1 home]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm
#安裝mysql-server
[root@slave1 home]# yum install mysql-server
#啓動mysql
[root@slave1 home]# systemctl start mysqld
#開機啓動
[root@slave1 home]# systemctl enable mysqld
#查看狀態
[root@slave1 home]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-06-04 16:00:23 CST; 18s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 27140 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 27077 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 27143 (mysqld)
CGroup: /system.slice/mysqld.service
└─27143 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jun 04 16:00:06 slave1 systemd[1]: Starting MySQL Server...
Jun 04 16:00:23 slave1 systemd[1]: Started MySQL Server.
#配置mysql密碼
#獲取初始密碼
[root@slave1 home]# grep 'temporary password' /var/log/mysqld.log
2020-06-04T08:00:20.783779Z 1 [Note] A temporary password is generated for root@localhost: 9cVXGPq-W-.m
#登錄
[root@slave1 home]# mysql -uroot -p9cVXGPq-W-.m
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.30
Copyright (c) 2000, 2020, 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> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
#修改密碼
mysql> SET PASSWORD = PASSWORD('passw0rd');
Query OK, 0 rows affected, 1 warning (0.00 sec)
#刷新權限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
#退出
mysql> exit
Bye
#測試新密碼
[root@slave1 home]# mysql -uroot -ppassw0rd
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 9
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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>