在mysql官网获取yum源安装包
http://dev.mysql.com/downloads/repo/yum/
复制下载链接地址为:
mysql80-community-release-el7-3.noarch.rpm
//安装
wget http://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql80-community-release-el7-5.noarch.rpm
yum install mysql-community-server -y
//检查是否开机启动
systemctl list-unit-files|grep mysqld
//显示以下为开机启动
mysqld.service enabled
mysqld@.service disabled
//如果没有设置为开机启动则执行
systemctl enable mysqld.service
//修改数据库存储路径
https://zhuanlan.zhihu.com/p/39426856
vim /etc/my.cnf
datadir=/data/user/scm/mysql(制定为新的数据存放目录,开启服务会自动创建该目录)
//将目录授权给mysql用户组
chown mysql:mysql -R /data/user/scm/mysql
chmod 777 /data/user/scm/mysql
//设置默认编码为 utf8,修改 /etc/my.cnf 配置文件,在相关节点(没有则自行添加,mysqld是已有节点)下添加编码配置,如下:
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
//启动mysql服务
systemctl start mysqld
systemctl status mysqld
//查看MySQL初始默认密码
grep 'temporary password' /var/log/mysqld.log
//通过初始密码登录
mysql -u root -p
//修改新密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
//开启MySQL远程连接
mysql -u root -p
mysql> use mysql;
#修改root账户权限
mysql> update user set host = '%' where user = 'root';
#刷新权限
mysql> flush privileges;
#查看默认编码
mysql> show variables like 'character%';
//此时mysql已经启动成功,可以通过navicat等工具连接,navicat版本12.1以下的由于驱动未更新,会报错(Authentication plugin ' caching _ sha 2 _ password cannot be loaded : The speaified module could not be found)
需要修改mysql的加密规则,mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password。解决问题方法有两种:方法1.升级navicat驱动;方法2.把mysql用户登录密码加密规则还原成mysql_native_password.。此处使用的是方法2
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码'; 或者 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
mysql> flush privileges;
//如果报错ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
ERROR 1396 (HY000): Operation ALTER USER failed for ‘root‘@‘localhost‘_JAVA|Mr.Java的博客-CSDN博客