#初始化
mysqld --initialize
#更改所属组chown mysql:mysql /var/lib/mysql -R
#启动mysql
systemctl start mysqld.service
#查看生成的临时root密码cat /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: o+TU+KDOm004
1.4. 修改root密码 授权远程访问 设置开机自启动
[root@node2 ~]# mysql -u root -p
Enter password: #这里输入在日志中生成的临时密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29
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>#更新root密码 设置为hadoop
mysql> alter user user() identified by "123456";
Query OK, 0 rows affected (0.00 sec)#授权
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql>exit#mysql的启动和关闭 状态查看 (这几个命令必须记住)
systemctl stop mysqld
systemctl status mysqld
systemctl start mysqld
#建议设置为开机自启动服务[root@node2 ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
#查看是否已经设置自启动成功[root@node2 ~]# systemctl list-unit-files | grep mysqld
mysqld.service enabled