#查看MySQL用户组
[root@localhost opt]# cat /etc/group | grep mysql
#创建MySQL用户组
[root@localhost opt]# groupadd mysql
#创建MySQL用户,并加入MySQL用户组
[root@localhost opt]# useradd -g mysql mysql
#启动MySQL服务
[root@localhost mysql-8.0.31]# service mysql start
Starting MySQL....SUCCESS!
#查看状态
[root@localhost mysql-8.0.31]# service mysql status
SUCCESS! MySQL running(6472)
#停止MySQL服务
service mysql stop
#查看状态
service mysql status
#重启MySQL命令
service mysql restart
8.登录MySQL并配置
查看临时密码,并登陆MySQL
[root@localhost ~]# cat /opt/mysql-8.0.31/log/mysql-error.log
2022-11-21T03:11:58.379381Z 6[Note][MY-010454][Server]A temporary password is generated for root@localhost:;&kPlxCXF9Hi
登录,修改root密码并设置远程访问
#登录
[root@localhost ~]# mysql -P5306 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.31
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Ys_20221107';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
#设置远程访问
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql>quit