大家好,我是Jaylon,配置安装环境一直是令菜鸡程序员头疼的事,网上资源良莠不齐,写的很复杂,还得自己试错,所以少说废话,上干货~~~
Linux 下安装MySQL8 | |
步骤 | Linux 命令 |
1. 下载压缩包: | wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz |
2. 解压安装: | tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64 |
3. 移动并重命名: | mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql |
4. 创建mysql用户组: | groupadd mysql |
5. 创建mysql用户并修改权限: | useradd -r -g mysql mysql (通过cat /etc/passwd查看新建用户) |
6. 创建mysql数据目录: | mkdir -p /data/mysql |
7. 赋予权限: | chown mysql:mysql -R /data/mysql |
8. 配置my.cnf: | vi /etc/my.cnf (修改成如下配置: [mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/usr/local/mysql datadir=/data/mysql socket=/tmp/mysql.sock symbolic-links=0 character_set_server=utf8mb4 [mysqld_safe] #log-error=/var/log/mariadb/mariadb.log log-error=/data/mysql/mysql.err #pid-file=/var/run/mariadb/mariadb.pid pid-file=/data/mysql/mysql.pid [client] port=3306 socket=/tmp/mysql.sock !includedir /etc/my.cnf.d ) |
9. 初始化数据库: | 1. 进入目录: cd /usr/local/mysql/bin 2. 初始化: ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize (这里会报错:【初始化失败】./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory) 3. 安装缺失的东西:yum install -y libaio-devel.x86_64 4. 重新初始化: ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize (运行成功后会有一个temporary password,记下来,后面登陆会用到) |
10. 复制服务文件: | cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql (这一步很关键,可以使用find /etc/init.d/ -name mysql查看复制是否成功) |
11. 启动mysql服务: | systemctl start mysql (提示:Starting MySQL. ) |
后续首次登陆需要修改密码:
|
互联网寒气逼人,大家都要加油呀!over~