部署mysql-8.0.22

下载地址:https://downloads.mysql.com/archives/community/
在这里插入图片描述
步骤一、解压

# cd /opt
# tar -xf mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz
# mv mysql-8.0.22-linux-glibc2.12-x86_64 mysql8

步骤二、创建用户

# groupadd mysql
# useradd -r -g mysql mysql

步骤三、创建mysql数据目录data

# mkdir -p /data/mysql8_data
# chmod -R 755 /data/mysql8_data/
# chown mysql:mysql -R /data/mysql8_data

步骤四、编写配置文件

# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql8_data/
socket=/data/mysql8_data/mysql.sock
symbolic-links=0
[client]
socket=/data/mysql8_data/mysql.sock          #指定mysql.sock,不然有可能出现ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)报错
[mysqld_safe]
log-error=/data/mysql8_data/mysql.log
pid-file=/data/mysql8_data/mysql.pid

步骤五、初始化mysql

# cd /opt/mysql8/bin
# ./mysqld --defaults-file=/etc/my.cnf --basedir=/opt/mysql8/ --datadir=/data/mysql8_data/ --user=mysql --initialize

初始密码可以查看mysql.log
在这里插入图片描述

步骤六、启动mysql

# cd /opt/mysql8
# cp -a ./support-files/mysql.server /etc/init.d/mysql
# chown 777 /etc/my.cnf
# chmod +x /etc/init.d/mysqld
# mkdir /var/lib/mysql
# chown -R mysql:mysql /var/lib/mysql/
# service mysql start
/etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQLCouldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)[FAILED]

此时会报错,是因为启动命令路径不一样导致
解决方法:

# vim support-files/mysql.server
basedir=/opt/mysql8
# cp -a ./support-files/mysql.server /etc/init.d/mysql
# chmod +x /etc/init.d/mysql
# chkconfig --add mysql
# chkconfig --list mysql
# service mysql start
Starting MySQL..[  OK  ]

步骤七、登录mysql进行密码更新

# mysql -uroot -p

> ALTER USER 'root'@'localhost' IDENTIFIED with mysql_native_password BY '你的新密码';
> flush privileges; #刷新权限

> use mysql;
> select user,host,plugin,authentication_string from user;
> CREATE user 'root'@'%'; #创建用户任意远程访问
> alter user 'root'@'%' identified with mysql_native_password by 'root'; #修改密码
> grant all privileges on *.* to "root"@"%"; #给用户授权
> flush privileges; #刷新权限
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值