突然发现mysql都有8.0了,且性能提升比较明显,就自己装来玩玩。
centos的yum源中默认是没有mysql的,所以我们需要先去官网下载mysql的repo源并安装;
官网:http://dev.mysql.com/downloads/repo/yum/
#rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
#yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 24
mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 38
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-preview/x86_64 MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - Sourc 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 禁用
mysql56-community-source MySQL 5.6 Community Server - Sourc 禁用
mysql57-community/x86_64 MySQL 5.7 Community Server 启用: 267
mysql57-community-source MySQL 5.7 Community Server - Sourc 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 禁用
mysql80-community-source MySQL 8.0 Community Server - Sourc 禁用
这里显示的是5.7的包,我们可以修改源文件,禁用5.7,启用8.0
#/etc/yum.repos.d/mysql-community.repo
把8.0enabled改为1就可以了,其他的版本改为0
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
修改完成之后查看可用的版本
#yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 24
mysql-tools-community/x86_64 MySQL Tools Community 38
mysql57-community/x86_64 MySQL 8.0 Community Server 146
如果看到8.0版本启用了之后就可以安装MySql了
#yum install -y mysql-community-server (过程会稍微有些慢,耐心等待)
安装完成之后,就可以启动mysql了
#systemctl start mysqld
查看MySql的启动状态
#systemctl status mysqld
Redirecting to /bin/systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2018-05-11 23:34:51 CST; 11s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 12421 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 12661 (mysqld) Status: "SERVER_OPERATING" CGroup: /system.slice/mysqld.service └─12661 /usr/sbin/mysqld May 11 23:34:42 VM_0_7_centos systemd[1]: Starting MySQL Server... May 11 23:34:51 VM_0_7_centos systemd[1]: Started MySQL Server.
开机启动设置
#systemctl enable mysqld
#systemctl daemon-reloadMySql安装完成之后会在LOG文件(/var/log/mysqld.log)中生成一个root的默认密码
#grep 'temporary password' /var/log/mysqld.log
2018-05-11T15:34:46.440387Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hqm8r1xXy3<r
登录MySql并修改root密码
#mysql -uroot -p
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new psd';#密码强度默认为中等,大小写字母、数字、特殊符号,只有修改成功后才能修改配置再设置更简单的密码
扩展阅读:mysql的密码策略
mysql>show variables like '%validate_password%';
+---------------------------------------+--------+ | Variable_name | Value | +---------------------------------------+--------+ | validate_password_check_user_name | ON | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +---------------------------------------+--------+ 7 rows in set (0.01 sec)
默认的密码策略
validate_password_policy:密码策略,默认为MEDIUM策略 validate_password_dictionary_file:密码策略文件,策略为STRONG才需要 validate_password_length:密码最少长度 validate_password_mixed_case_count:大小写字符长度,至少1个 validate_password_number_count :数字至少1个 validate_password_special_char_count:特殊字符至少1个
修改密码策略
在/etc/my.cnf文件添加validate_password_policy配置:
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件 validate_password_policy=0
或者set global validate_password.policy=0;
修改默认编码
在/etc/my.cnf配置文件的[mysqld]下添加编码配置:
[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
重启mysql,是修改生效
#systemctl restart mysqld
远程登录用户添加
mysql> GRANT ALL PRIVILEGES ON . TO 'admin'@'%' IDENTIFIED BY '*****' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;查看用户
mysql> select host,user from mysql.user;
+-----------+------------------+ | host | user | +-----------+------------------+ | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+------------------+ 4 rows in set (0.00 sec)
搞定~
我的系统SELinux默认是disable的,所以就不管了。
vim /etc/selinux/config,把SELINUX改为disable即可。
增加3306端口:vim /etc/sysconfig/iptables添加-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
强调:navicat连接mysql8.0的话会报2059(解决方法:https://blog.csdn.net/qq_29932025/article/details/80045716)
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。