Linux安装MYSQL8.0

1.下载mysql

cd /usr/local/src 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
也可以直接在官方下载最新版本 https://dev.mysql.com/downloads/mysql/ 选择linux

2.解压到指定目录

tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz  -C /usr/local/

3.重命名

cd /usr/local/
mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql

4.在mysql根目录下创建data目录,存放数据

cd /usr/local/mysql/
mkdir data

5.创建mysql用户组和mysql用户

groupadd mysql
useradd -g mysql mysql

6.改变mysql目录权限

chown -R mysql.mysql /usr/local/mysql/

7.切换到bin目录下

cd /usr/local/mysql/bin

7.初始化数据库

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

得到临时密码:
在这里插入图片描述

8.配置mysql
在mysql/support-files创建文件my-default.cnf

1. cd /usr/local/mysql/support-files/
2. touch my-default.cnf

复制配置文件到/etc/my.cnf

cp -a ./my-default.cnf /etc/my.cnf 

编辑my.cnf

vim /etc/my.cnf

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

9.添加mysqld服务到系统

cd /usr/local/mysql
cp -a ./support-files/mysql.server /etc/init.d/mysql

10.授权以及添加服务

chmod +x /etc/init.d/mysql
chkconfig --add mysql

11.启动mysql

 service mysql start

12.查看启动状态

service mysql status

13.将mysql命令添加到服务

ln -s /usr/local/mysql/bin/mysql /usr/bin

14.修改密码:登录mysql, mysql -uroot -p 密码使用之前随机生成的密码

1. mysql -uroot -p
 提示:mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
解决方法:
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

修改root密码 ,其中123456是新的密码自己设置
2. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; 
3.  flush privileges;  #执行,使密码生效
4.   use mysql;  #选择mysql数据库

修改远程连接并生效 
5.  update user set host='%' where user='root';
6.  flush privileges;

你可能感兴趣的:(mysql,Nginx,linux,mysql,服务器)