Linux离线安装MySQL
程序员文章站
2024-03-21 18:24:16
...
服务器:阿里云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. 解压安装包
[aaa@qq.com local]# tar -zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
解压后在“/usr/local”下面会多一个目录“mysql-5.7.32-linux-glibc2.12-x86_64”
将这个目录重命名为mysql
[aaa@qq.com local]# mv mysql-5.7.32-linux-glibc2.12-x86_64 mysql
4. 创建mysql用户组及用户,并给mysql用户设置密码
[aaa@qq.com local]# groupadd mysql
[aaa@qq.com local]# useradd -r -g mysql mysql
[aaa@qq.com local]# passwd mysql
Changing password for user mysql.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
5. 在mysql目录下新建data文件夹用于存放数据库文件
[aaa@qq.com local]# cd mysql
[aaa@qq.com mysql]# mkdir data
6. 在mysql当前目录下设定目录的访问权限
注:后面的小点,表示当前目录
[aaa@qq.com mysql]# chown -R mysql .
[aaa@qq.com mysql]# chgrp -R mysql .
[aaa@qq.com mysql]# ll
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
[aaa@qq.com mysql]#
7. 初始化数据库
[aaa@qq.com mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
注:在执行完上述命令后
这个密码就是root的初始密码
8. 启动mysql
[aaa@qq.com mysql]# ./support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/iZm5e0ruj2b7jdo68j6u4nZ.err'.
[ OK ]
9. 登录mysql,修改root用户密码
[aaa@qq.com mysql]# ./bin/mysql -uroot -p
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允许远程访问
[aaa@qq.com mysql]# ./bin/mysql -uroot -p
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的启动、停止、重启命令
[aaa@qq.com mysql]# ./support-files/mysql.server start #启动命令
Starting MySQL. [ OK ]
[aaa@qq.com mysql]# ./support-files/mysql.server restart #重启命令
Shutting down MySQL.. [ OK ]
Starting MySQL. [ OK ]
[aaa@qq.com mysql]# ./support-files/mysql.server stop #停止命令
Shutting down MySQL.. [ OK ]
[aaa@qq.com mysql]#