服务器:阿里云ECS 系统版本:CentOS Linux release 8.2.2004 (Core)
1.下载MySQL安装包
下载地址:https://dev.mysql.com/downloads/mysql/
2. 将mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz上传到Linux的“/usr/local”目录下
3. 解压安装包
[root@iZm5e0ruj2b7jdo68j6u4nZ local
]
解压后在“/usr/local”下面会多一个目录“mysql-5.7.32-linux-glibc2.12-x86_64” 将这个目录重命名为mysql
[root@iZm5e0ruj2b7jdo68j6u4nZ local
]
4. 创建mysql用户组及用户,并给mysql用户设置密码
[root@iZm5e0ruj2b7jdo68j6u4nZ local
]
[root@iZm5e0ruj2b7jdo68j6u4nZ local
]
[root@iZm5e0ruj2b7jdo68j6u4nZ local
]
Changing password
for user mysql.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
5. 在mysql目录下新建data文件夹用于存放数据库文件
[root@iZm5e0ruj2b7jdo68j6u4nZ local
]
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
6. 在mysql当前目录下设定目录的访问权限
注:后面的小点,表示当前目录
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
total 260
drwxr-xr-x 2 mysql mysql 4096 Oct 21 09:12 bin
drwxr-xr-x 2 mysql mysql 6 Oct 21 09:16 data
drwxr-xr-x 2 mysql mysql 55 Oct 21 09:12 docs
drwxr-xr-x 3 mysql mysql 4096 Oct 21 09:12 include
drwxr-xr-x 5 mysql mysql 230 Oct 21 09:12 lib
-rw-r--r-- 1 mysql mysql 247914 Sep 23 20:00 LICENSE
drwxr-xr-x 4 mysql mysql 30 Oct 21 09:12
man
-rw-r--r-- 1 mysql mysql 587 Sep 23 20:00 README
drwxr-xr-x 28 mysql mysql 4096 Oct 21 09:12 share
drwxr-xr-x 2 mysql mysql 90 Oct 21 09:12 support-files
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
7. 初始化数据库
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
注:在执行完上述命令后 这个密码就是root的初始密码
8. 启动mysql
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
Starting MySQL.Logging to
'/usr/local/mysql/data/iZm5e0ruj2b7jdo68j6u4nZ.err'.
[ OK
]
9. 登录mysql,修改root用户密码
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
Enter password:
Welcome to the MySQL monitor. Commands end with
; or \g.
Your MySQL connection
id is 2
Server version: 5.7.32
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
> alter user
'root'@
'localhost' identified by
'123456';
Query OK, 0 rows affected
(0.01 sec
)
mysql
> exit
Bye
10. 配置mysql允许远程访问
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
Enter password:
Welcome to the MySQL monitor. Commands end with
; or \g.
Your MySQL connection
id is 3
Server version: 5.7.32 MySQL Community Server
(GPL
)
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
> CREATE USER
'root'@
'%' IDENTIFIED BY
'123456';
Query OK, 0 rows affected
(0.00 sec
)
mysql
> grant all privileges on *.* to
'root'@
'%' with grant option
;
Query OK, 0 rows affected
(0.00 sec
)
mysql
> flush privileges
;
Query OK, 0 rows affected
(0.00 sec
)
mysql
> exit
Bye
11. mysql的启动、停止、重启命令
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
Starting MySQL.
[ OK
]
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
Shutting down MySQL
.. [ OK
]
Starting MySQL.
[ OK
]
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]
Shutting down MySQL
.. [ OK
]
[root@iZm5e0ruj2b7jdo68j6u4nZ mysql
]