一、下载linux mysql8.0 离线安装包
mysql下载地址:https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
mysql官方下载最新版本:https://dev.mysql.com/downloads/mysql/
然后选择 linux
把下载的压缩包上传到要安装的服务器上,解压mysql tar xvJf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
二、安装mysql
在 /usr/local
目录下创建mysql文件夹 mkdir mysql
切换到mysql目录下 cd /usr/local/mysql
# 解压mysql [root@localhost /usr/local/mysql]# tar mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz # 移动/重命名文件夹 [root@localhost /usr/local/mysql]# mv mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz mysql-8 # 创建 data 文件夹 储存文件 [root@localhost /usr/local/mysql]# cd mysql-8 [root@localhost /usr/local/mysql/mysql-8# mkdir data # 创建用户组以及用户和密码 [root@localhost /usr/local/mysql/mysql-8]# groupadd mysql [root@localhost /usr/local/mysql/mysql-8]# useradd -g mysql mysql # 授权用户 [root@localhost /usr/local/mysql/mysql-8]# chown -R mysql.mysql /usr/local/mysql/mysql-8 # 切换到bin目录下,初始化基础信息 [root@localhost /usr/local/mysql/mysql-8]# cd bin [root@localhost /usr/local/mysql/mysql-8/bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8 --datadir=/usr/local/mysql/mysql-8/data/ --initialize --lower-case-table-names=1
得到临时密码
编辑 my.cnf
(没有就新建一个 touch my.cnf
) vim /etc/my.cnf 注释mysqld_safe
[mysqld] basedir=/usr/local/mysql/mysql-8/ datadir=/usr/local/mysql/mysql-8/data/ socket=/tmp/mysql.sock character-set-server=UTF8MB4 lower_case_table_names = 1 bind-address=0.0.0.0 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
#进入/usr/local/mysql/mysql-8目录
[root@localhost bin]# cd /usr/local/mysql/mysql-8
# 添加mysqld服务到系统 [root@localhost /usr/local/mysql/mysql-8]# cp -a ./support-files/mysql.server /etc/init.d/mysql # 授权以及添加服务 [root@localhost /usr/local/mysql/mysql-8]# chmod +x /etc/init.d/mysql [root@localhost /usr/local/mysql/mysql-8]# chkconfig --add mysql # 启动 mysql [root@localhost /usr/local/mysql/mysql-8]# service mysql start # 停止 mysql [root@localhost /usr/local/mysql/mysql-8]# service mysql stop # 重启 mysql [root@localhost /usr/local/mysql/mysql-8]# service mysql restart # 查看启动状态 [root@localhost /usr/local/mysql/mysql-8]# service mysql status # 将mysql命令添加到服务 [root@localhost /usr/local/mysql/mysql-8]# ln -s /usr/local/mysql/mysql-8/bin/mysql /usr/bin # 登录mysql(使用临时密码) [root@localhost /usr/local/mysql/mysql-8]# mysql -uroot -p
# 修改root密码并刷新使密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxxx'; flush privileges; # 选择mysql数据库 use mysql; # 修改远程连接并生效 update user set host='%' where user='root'; flush privileges;
标签:root,linux,离线,mysql8.0,usr,mysql,local,localhost From: https://www.cnblogs.com/fxrz/p/18156006