linux 安装mysql 8.0 并开机自启

1:安装依赖 
yum -y install wget  cmake gcc gcc-c++ ncurses  ncurses-devel  libaio-devel  openssl openssl-devel

2:下载源码包
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.11.tar.gz

3:创建mysql用户
groupadd mysql     useradd -r -g mysql -s /bin/false mysql

4:新建mysql 安装目录和数据目录

mkdir /usr/local/mysql   ###安装目录
mkdir /data
cd /data
mkdir mysql              ###数据目录

5:解压
tar -zxvf mysql-boost-8.0.11.tar.gz -C /usr/local

6:切换到mysql解压目录
cd /usr/local/mysql-8.0.11

7:编译安装(mysql8.0编译安装需要2G 内存 所以要确保内存够,不然会编译出错的)
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.11/boost

make && make install   (开始编译大概一小时左右)

8:创建组和用户
groupadd mysql
useradd -g mysql mysql

9:目录权限修改
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql
chmod 755 /usr/local/mysql -R
chmod 755 /data/mysql -R

10:初始化mysql
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql  --basedir=/usr/local/mysql --datadir=/data/mysql
bin/mysql_ssl_rsa_setup

11:修改配置文件
vim /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data/
socket=/tem/mysql.sock
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
log-error=/var/log/mysqld.log
port=3306

12: 创建进程文件目录
mkdir /var/run/mysqld
chown mysql /var/run/mysqld/ -R

13:启动mysql
cd /usr/local/mysql/support-files
./mysql.server start              ###启动mysql

14:进入到mysql
cd /usr/local/mysql
bin/mysql -u root -p
Entry Password:输入初始化密码

15:修改初始化密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';   password为你要修改之后的密码

16:刷新权限
flush privileges;

17:修改 host
use mysql;
update user set host='%' where user='root';

18:允许远程连接
赋权限 all 表示所有权限(select,update等) %表示允许所有地址 也可以是具体的ip地址
grant all privileges on *.* to 'root'@'%' with grant option;

19:开放3306端口
permanent 表示永久开启
firewall-cmd --add-port=3306/tcp  --permanent

20:重启防火墙
systemctl start firewalld

21:mysql开机自启
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

22:赋予可执行权限
chmod +x /etc/init.d/mysql

23:添加服务
chkconfig --add mysql

24:开关mysql服务
service mysql start  ##开启服务
service mysql stop   ##关闭服务
 

 

你可能感兴趣的:(linux,mysql8.0)