MySQL5.7在Centos6.5下的安装

时间:2022-09-13 21:06:26

下载MySQL5.7

https://dev.mysql.com/downloads/mysql/

一般情况下载server,client,common,libs即可。

In most cases, you need to install the mysql-community-servermysql-community-clientmysql-community-libsmysql-community-common, and mysql-community-libs-compat packages to get a functional, standard MySQL installation. To perform such a standard, minimal installation, go to the folder that contains all those packages (and, preferably, no other RPM packages with similar names).

安装

检查MySQL及相关RPM包,是否安装,如果有安装,则移除

rpm -qa | grep -i mysql

yum remove 包名

安装MySQL

rpm -ivh mysql-community-{server,client,common,libs}-*

 启动MySQL,已经初始化常用操作

启动MySQL

 service mysqld start

设置MySQL初始密码

grep 'temporary password' /var/log/mysqld.log

登录MySQL

mysql -uroot -p

修改MySQL初始密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

编码设置

修改/etc/my.cnf文件,修改之后需要重启MySQL

[mysqld]
character
-set-server=utf8

创建远程连接用户

CREATE USER 'exam'@'%' IDENTIFIED BY 'Ud6^Grda';

GRANT ALL PRIVILEGES ON *.* TO 'exam'@'%' WITH GRANT OPTION;

flush
privileges;

导入数据

source .../exam.sql

兼容旧版MySQL的group by语句

修改/etc/my.cnf文件,修改之后需要重启MySQL

[mysqld]
sql_mode
=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

去掉了默认的ONLY_FULL_GROUP_BY

开放3306端口

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save