1.从官网下载压缩包:链接地址:wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
2.解压: tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
3.安装依赖:
yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel
4.创建用户组:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
5.创建安装目录
mkdir -p /usr/local/mysql
6.创建数据目录
mkdir -p /usr/local/mysql/data
7.初始化数据库
cd /usr/local/mysql
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
这个时候会初始化一个数据库密码,记录下来‘root@localhost: 9cmht#5pe(pQ’
8.创建软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
9.修改my.cnf文件,内容如下:basedir为数据库安装路径,datadir为数据库数据路径,log-error和pid-file为日志和pid路径
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
10. 复制cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld,并修改mysqld文件内容:
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
11.创建/var/log/mysql/mysql.log和/var/run/mysql/mysql.pid
mkdir -p /var/log/mysql --创建目录
touch mysql.log --创建文件
mkdir -p /var/run/mysql --创建目录
touch mysql.pid --创建文件
12.赋权限
chown -R mysql:mysql /var/log/mysql
chown -R mysql:mysql /var/run/mysql
chmod 750 /var/log/mysql/mysql.log
chomd 750 /var/run/mysql/mysql.pid
13.创建软连接
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
14.MySQL相关命令
service mysqld start --启动mysql
service mysqld stop --关闭mysql
service mysqld restart --重启mysql
15.登陆mysql,输入第七步初始化生成的密码
mysql -uroot -p
16.修改root用户密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
17.查看mysql版本
SELECT VERSION();
18.给root用户赋权限,将用户的host从locahost(本地访问)改为%(远程访问)
GRANT ALL ON *.* TO 'root'@'%';
如果执行此命令报没有权限,则重新创建一个root用户host为%
CREATE USER 'root'@'%' IDENTIFIED BY 'root'; --创建root用户,host为%
19.给%的root用户赋所有权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
20.修改root用户密码规则
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
21. 刷新权限
FLUSH PRIVILEGES;
22.关闭防火墙,或者给3306端口添加规则
systemctl stop firewalld.service --关闭防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent --添加3306端口
firewall-cmd --reload --重启防火墙规则