mysql8 centos7 setup

mysql 8

Install MySQL YUM repository and mysql

Start MySQL server and autostart MySQL on boot

  • systemctl start mysqld.service ## use restart after update
  • systemctl enable mysqld.service

Get Your Generated Random root Password

1
grep 'A temporary password is generated for root@localhost' /var/log/mysqld.log |tail -1

Example Output:
2015-11-20T21:11:44.229891Z 1 [Note] A temporary password is generated for root@localhost: -et)QoL4MLid
And root password is: -et)QoL4MLid

Connect to MySQL database (localhost) with password

1
mysql -u root -p

会提示修改密码

1
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Python3&&890';

但是至此是不能从远程访问此mysqld

enable root remote access

1
2
3
use mysql;
UPDATE user SET host = '%' WHERE user = 'root';
flush privileges;

create user and enable remote access

1
2
3
4
use mysql;
CREATE USER 'xuhang'@'%' IDENTIFIED BY 'Python3&&890'; -- 创建用户
GRANT ALL ON *.* TO 'xuhang'@'%' WITH GRANT OPTION; -- 授权
flush privileges;

backup data

1
2
3
4
5
// backup all db
mysqldump --all-databases -uroot -p> /tmp/dump.sql

// backup specific db
mysqldump --databases test1 -uroot -p> /tmp/dump.sql

recover data

1
2
mysql -uroot -p
source /tmp/dump.sql

reference