linux下mysql8.0安装详细教程

1.下载官方安装包  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

2.解压程序包

tar -zxvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

3.移动到 /usr/local/mysql 下 

cp mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql -r

4.新建用户和用户组并进入mysql 文件下赋予权限

cd /usr/local/mysql/
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql ./

5.初始化数据库 (mysql 8.0版本没有./scripts/mysql_install_db) 

 mkdir ./data
./bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize ;

注意:记住临时密码

6.配置mysql

vi /etc/my.cnf

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
character-set-server=utf8

7.把msyql 添加到系统服务

cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql #权限
chkconfig --add mysql
chkconfig --list mysql #检查是否生效

8.启动服务 

service mysql start
#检查服务状态
service mysql status;

9.登陆mysql (使用初始密码)

mysql -uroot -p

#若报错 -bash: mysql: command not found
执行下面命令 否则略过这部分
ln -s /usr/local/mysql/bin/mysql /usr/bin #建立软连接
软连接已存在的情况 进去目录usr/bin 删除连接 重新建立

[root@instance-6olzww4q bin]# rm mysql 
rm: remove symbolic link 'mysql'? y

10.修改密码和用户权限

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'abc123';
FLUSH PRIVILEGES;

 

你可能感兴趣的:(每日异常)