使用root账号安装
一、预安装环境
yum install gcc gcc-c++ openssl openssl-devel libaio libaio-devel ncurses
ncurses-deve yum -y install numactl
二、准备mysql相关安装文件、环境
下载
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12
-x86_64.tar.gz
解压
tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
建立mysql的安装目录
mkdir /usr/local/mysql8
把相关文件复制过去
cp -r mysql-8.0.11-linux-glibc2.12-x86_64/* /usr/local/mysql8/ cd
/usr/local/mysql8
建立数据和错误日志的目录
mkdir data mkdir log
初始化数据库目录
/usr/local/mysql8/bin/mysqld --initialize --user=mysql --
basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data
添加环境目录
echo "export PATH=$PATH:/usr/local/mysql8/bin" >> /etc/profile source
/etc/profile
三、配置文件和启动脚本
制作配置文件
vi /etc/my.cnf port=3306 datadir=/usr/local/mysql8/data log-error=/usr/local
/mysql8/log/mysql-err.log user=root skip-grant-tables #此项是为了装好后免登陆修改密码使用
default_authentication_plugin=mysql_native_password [client]
socket=/tmp/mysql.sock
制作启动脚本
复制一个过去
cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld vi /etc/init
.d/mysqld
编辑mysqld文件,找到这两个配置项,改成当前配置
basedir=/usr/local/mysql8 datadir=/usr/local/mysql8/data
启动、关闭、重启mysql的命令
/etc/init.d/mysqld start /etc/init.d/mysqld stop /etc/init.d/mysqld restart
四、重置密码
mysql -u root -p
到输入密码的时候直接回车
use mysql
先清空root的密码
mysql>update user set authentication_string = '' where user = 'root'; quit
删掉my.cnf里的句
skip-grant-tables
重启mysql
/etc/init.d/mysqld restart
然后再进去,还是到输入密码的时候直接回车,已经将密码置空了
mysql -u root -p
修改密码,这里注意一下,密码强度是有要求的,这也是MYSQL8的特性
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; mysql>use
mysql;
修改登录IP限制,不修改就只能本地登录
mysql>update user set host = '%' where user = 'root';
重新刷新一下,因为有的时候用远程工具连接会有问题
mysql>ALTER USER 'root'@'%' IDENTIFIED BY 'MyNewPass4!' PASSWORD EXPIRE NEVER;
mysql>ALTER USER'root'@'%' IDENTIFIED WITH mysql_native_password BY
'MyNewPass4!';
好了,用数据库的远程工具连接上可以用了
热门工具 换一换