赞
踩
https://dev.mysql.com/downloads/mysql/
这里我下载的是64位版本,且注意是tar.xz格式的压缩包
#进入usr/local目录
cd /usr/local/
xz -d mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.31-linux-glibc2.12-x86_64.tar
mv mysql-8.0.31-linux-glibc2.12-x86_64 mysql8
- cd mysql8
- mkdir data
- groupadd mysql
- useradd -g mysql mysql
- chown -R mysql.mysql /usr/local/mysql8/
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data
注:运行指令后将会出现如下输出,记住临时密码,每次运行上述指令生成的临时密码都不一样,我这里是:BR9Z6seB%P7z
vim /etc/my.cnf
- [mysqld]
- basedir=/usr/local/mysql8
- datadir=/usr/local/mysql8/data
- socket=/tmp/mysql.sock
- character-set-server=utf8
- default_authentication_plugin=mysql_native_password
- port=3306
ESC退出编辑,:wq保存退出
# 添加Mysql到系统服务(当前目录应为:/usr/local/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
#查看状态
service mysql status
#登录mysql可能会出现如下错误
解决办法:
ln -s /usr/local/mysql8/bin/mysql /usr/bin
#登录mysql
mysql -uroot -p
#输入或粘贴之前记录的临时密码并回车:BR9Z6seB%P7z
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
- create user root@'%' identified by '新密码';
- grant all privileges on *.* to root@'%' with grant option;
#刷新权限
flush privileges;
#查看设置结果
- use mysql;
- select host,user,plugin,authentication_string from user;
#编辑 / etc/profile 文件
vi /etc/profile
#在文件底部添加,保存退出
- export PATH=$PATH:/usr/local/mysql8/bin:/usr/local/mysql8/lib
- export PATH
#刷新配置
source /etc/profile
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。