1.安装MySQL
解压:
[root@13 ~]# tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar
mysql-test-8.0.33-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
mysql-router-8.0.33-linux-glibc2.12-x86_64.tar.xz
继续解压:
[root@13 ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.gz
2.进入解压后目录:
[root@13 ~]# cd mysql-8.0.33-linux-glibc2.12-x86_64/
[root@13 mysql-8.0.33-linux-glibc2.12-x86_64]#
[root@13 mysql-8.0.33-linux-glibc2.12-x86_64]# ls
bin docs include lib LICENSE man README share support-files
[root@13 mysql-8.0.33-linux-glibc2.12-x86_64]#
3.配置文件:
[root@13 mysql-8.0.33-linux-glibc2.12-x86_64]# vim support-files/mysql.server
4.移动文件
[root@13 ~]# cp -r mysql-8.0.33-linux-glibc2.12-x86_64/ /usr/local/mysql/
5.创建用户:
useradd -r -s /sbin/nologin mysql
6.创建目录:
[root@13 ~]# cd /usr/local/mysql
[root@13 mysql]# mkdir mysql-files
7.修改新创建的目录mysql-files权限:
[root@13 mysql]# chown mysql:mysql /usr/local/mysql/mysql-files/
[root@13 mysql]# chmod 750 /usr/local/mysql/mysql-files/
- 初始化数据库,找初始密码
[root@13 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/
2024-08-05T02:02:50.656813Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: s_LdCqDX-3q/
9.安全加密:
[root@13 ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
10.其他配置:
方便启动:
[root@13 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
11.启服务:
[root@13 mysql]# service mysql8 start
Starting MySQL... SUCCESS!
12.创建用户:
create user '用户名'@'%' identified by '密码'
mysql> create user 'hh'@'%' identified by '1Mysql@1'
-> ;
Query OK, 0 rows affected (0.29 sec)
mysql> exit
Bye
13.登录hh用户,查看全部表:
[root@15 ~]# mysql -u hh -p
Enter password:1Mysql@1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+
2 rows in set (0.03 sec)
mysql> exit
Bye
14.退出hh用户,进入root给hh用户添加权限:
[root@15 ~]# mysql -u root -p
mysql> grant all on *.* to "hh";
Query OK, 0 rows affected (0.06 sec)
mysql> exit
15.进入hh用户,查看全部表:
[root@15 ~]# mysql -u hh -p
Enter password: 1Mysql@1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql>