- 查看是否安装mysql
rpm -qa | grep mysql
- 检查是否自带mariadb数据库
rpm -qa|grep mariadb
有的话则删除
rpm -e --nodeps mariadb-libs
- linux下切到/usr/local新建mysql文件
mkdir mysql
- 切到mysql目录下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
- 解压
tar xvJf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
出错:
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
解决方法:
xz -d mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar
- 重命名
mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0
- 创建用户组以及用户和密码
groupadd mysql
useradd -g mysql mysql
- 授权用户
chown -R mysql.mysql /usr/local/mysql/mysql-8.0
- 切到bin目录下并初始化基础信息
cd /bin
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql/mysql-8.0/data/ --initialize
- 得到随机密码G(Ppve,B?5jo
- 编辑my.cnf文件
vi /etc/my.cnf
输入以下内容
[mysqld]
basedir=/usr/local/mysql/mysql-8.0/
datadir=/usr/local/mysql/mysql-8.0/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
- 添加mysqld服务到系统
cp -a ./support-files/mysql.server /etc/init.d/mysql
- 授权以及添加服务
chmod +x /etc/init.d/mysql
chkconfig --add mysql
- 启动mysql
service mysql start
- 查看启动状态
service mysql status
- 将mysql命令添加到服务
ln -s /usr/local/mysql/mysql-8.0/bin/mysql /usr/bin
- mysql -uroot -p 密码使用之前随机生成的密码
mysql -uroot -p
- 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
- 更新
flush privileges;
- 选择mysql数据库并允许远程连接
use mysql;
update user set host='%' where user='root';
flush privileges;