Centos 6.5安装Mysql8

踩过无数坑,用单一安装包、yum装都有各种问题。这里记录最后成功的方法,以备后续使用。

首先确定无同名mysql安装服务

查看原来安装的Mysql  
rpm -qa | grep mysql 
mysql-libs-5.1.71-1.el6.x86_64 

Mysql卸载
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64 

1、依赖包
yum install numactl libaio perl-Time-HiRes per-devel -y

2、mysql 官方下载安装包,这里我下载的是企业版(其它版本我也是一直装不上)

https://dev.mysql.com/downloads/file/?id=480720

3、用WinSCP传入linux服务器

4、tar -xvf mysql-8.0.0-0.1.dmr.el6.x86_64.rpm-bundle.tar

里面文件如下:

5、安装顺序如下:

rpm -ivh  mysql-community-common-8.0.13-1.el6.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.13-1.el6.x86_64.rpm

rpm -ivh mysql-community-libs-compat-8.0.13-1.el6.x86_64.rpm

rpm -ivh mysql-community-client-8.0.13-1.el6.x86_64.rpm

rpm -ivh mysql-community-server-8.0.13-1.el6.x86_64.rpm

6、启动(启动前,如果要mysql忽略大小写,要提前设置lower_case_table_names = 1,否则一但启动后就无法再修改了)

service mysqld start

查看启动状态

service mysqld status

设置开机启动   
chkconfig mysqld on
 

7、生成随机密码 
grep 'temporary password' /var/log/mysqld.log

8、使用随机密码登陆
mysql -uroot -p  

9、修改密码(这里直接修改为123456会提示密码太弱[非要改为123456,先要修改mysql8的密码规则],这里最好先将配置文件改了再来改密码,配置文件里面的密码规则影响navicat的登陆)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';  

10、授权远程连接

use mysql;

update user set host = '%' where user = 'root';

11、刷新配置
FLUSH PRIVILEGES;

12、打开防火墙

vim /etx/sysconfig/iptables

添加放开的端口(注意放置位置)

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT 

重启防火墙

service iptables start //开启防火墙

service iptables stop //关闭防火墙

service iptables restart //重启防火墙

#永久性生效,重启后不会复原(并不会即使生效,需要注意)

chkconfig iptables on #开启防火墙 

chkconfig iptables off #关闭防火墙,再次开机不会打开防火墙

再说my.cnf配置,在启动好后,/etc/my.cnf已经自动生成好了。后续争对mysql的配置优化肯定少不了,

比如默认端口3306 就看个人喜好改一个,避免恶意攻击。

比如,如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# 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

port=3369
character-set-server=utf8
max_connect_errors=10
max_connections=200
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


[mysql]
default-character-set=utf8
[client]
port=3369
default-character-set=utf8

猜你喜欢

转载自blog.csdn.net/mfkarj/article/details/83345225