centos下安装mysql8.0.12

2018-11-8

1、 下载

2、 解压

(1)tar -zvxf mysql-8.0.12-linux-glibc2.12-x86_64.tar 报错

(2)把z去掉

tar -vxf mysql-8.0.12-linux-glibc2.12-x86_64.tar

(3)再解压mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz

需要先安装xz: rpm -ivh xz-4.999.9-0.5.beta.20091007git.el6.x86_64.rpm

tar -xvf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz

3、重命名解压的文件假,并移动到你想的地方,如

mv mysql-8.0.12-linux-glibc2.12-x86_64 /eking/mysql

4、在/eking/mysql下建一个数据目录

mkdir data #后面初始化的时候要用

5、创建mysql用户和组,并把/eking/mysql目录赋给mysql用户

groupadd mysql

useradd -r -g mysql mysql

chown –R mysql.mysql /eking/mysql

6、初始化

/eking/mysql/bin/mysqld --initialize --user=mysql --basedir=/eking/mysql/ --datadir=/eking/mysql/data/

同时,记下初始密码

7、大小写敏感

没有/etc/my.cnf这个文件就建,可以借鉴参考配置,这步很重要,避免在重启后再配置,这时候无效果。

MySQL8.0想要 大小写不敏感,必须在安装好MySQL后 修改mySQL配置文件设置为不敏感,一旦启动后,再设置是无效的,而且启动报错。如果已经晚了,那必须把MySQL数据库文件全部 删除,修改配置文件再启动。

#让MYSQL大小写敏感(1-不敏感,0-敏感)/etc/my.cnf

lower_case_table_names=1

my.cnf参考配置:

[mysqld]

lower_case_table_names=1

#

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

#

# Remove the leading "# " to disable binary logging

# Binary logging captures changes between backups and is enabled by

# default. It's default setting is log_bin=binlog

# disable_log_bin

#

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

#

# Remove leading # to revert to previous value for default_authentication_plugin,

# this will increase compatibility with older clients. For background, see:

# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin

# default-authentication-plugin=mysql_native_password

datadir=/eking/mysql/data

socket=/tmp/mysql.sock

log-error=/var/log/mysqld.log

8、启动

/eking/mysql/bin/mysqld_safe --user=mysql & //启动

9、登录并修改密码

mysql -uroot -p 根据提示把前面记下的初始密码输入进行登录

ALTER USER 'root'@'localhost' IDENTIFIED BY '要修改的密码';

10、创建用户与授权

create user '用户名'@'%' identified by '密码'; #% 表示可以访问的客户端IP,%指任意IP地址

grant all privileges on *.* to '用户名'@'%';

flush privileges; #刷新权限

11、设置开机自启动

cp -a /eking/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/rc.d/init.d/mysqld

这样就可以用 service mysqld start 这样的命名启停了

12、注册服务

chkconfig --add mysqld #添加服务

chkconfig --list mysqld #查看服务是否添加成功

13、配置环境变量

vi /etc/profile #编辑profile文件

在最后面加入:export PATH=$PATH:/eking/mysql/bin:/eking/mysql/lib

source /etc/profile #使配置生效

14、远程登陆(解决Navicat 连接报 1251 错误)

出现这个原因是mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password, 解决问题方法有两种:一种是升级navicat驱动,一种是把mysql用户登录密码加密规则还原成mysql_native_password。

把mysql用户登录密码加密规则还原成mysql_native_password:

ALTER USER 'root' IDENTIFIED BY '修改的密码' PASSWORD EXPIRE NEVER; //修改加密规则

ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY '修改的密码'; //更新一下用户的密码

FLUSH PRIVILEGES; #刷新权限

15、应用连接MySQL8配置的调整

(1)数据库驱动修改成:com.mysql.cj.jdbc.Driver

(2)连接url串,后面要加上:&useSSL=false&serverTimezone=Asia/Shanghai

(3)如果是springboot的项目,要排除本身的mysql-connector-java