安装mysql
配置mysql的yum源
[root@VM-0-14-rockylinux ~]# tee /etc/yum.repos.d/mysql.repo << EOF
> [MYSQL]
> name=mysql
> baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64
> gpgcheck=0
> EOF
yum安装mysql
yum -y install mysql-community-server
设置开机自启动
systemctl enable --now mysqld
访问mysql
跳过密码验证(1045错误处理)
vim /etc/my.cnf
[mysqld]
skip-grant-tables
重启服务
systemctl restart mysqld
进入
修改密码
方法一
mysql> alter user root@'localhost' identified by '000000';
方法二
mysqladmin -uroot -p 初始密码 password 修改密码
初始化脚本提高安全性
[root@VM-0-14-rockylinux ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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> stastus
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stastus' at line 1
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.7.44, for Linux (x86_64) using EditLine wrapper
Connection id: 2
Current database:
Current user: root@
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.44 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 29 sec
Threads: 1 Questions: 6 Slow queries: 0 Opens: 97 Flush tables: 1 Open tables: 92 Queries per second avg: 0.206
--------------
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
都选y