1、检查是否已安装过mariadb,若有便删除(linux系统自带的)
[root@localhost /]# rpm -qa | grep mariadb [root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2、检查是否已安装过mysql,若有便删除(linux系统自带的)
[root@localhost /]# rpm -qa | grep mysql [root@localhost /]# rpm -e –-nodeps mysql-libs-5.1.52.x86_64
3、检查mysql组和用户是否存在,如无创建:
4、从官网下载mysql安装包,解压后移动到/usr/local/mysql下
[root@localhost download]# wget https:
//dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost download]# tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost download]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
5、在mysql下添加data目录
[root@localhost ~]# mkdir /usr/local/mysql/data
6、更改mysql目录下所有的目录及文件夹所属组合用户(一定不要少了 / ,之前就是这个原因搞了一天)
[root@localhost /]# cd /usr/local/ [root@localhost local]# chown -R mysql:mysql mysql/ [root@localhost local]# chmod -R 755 mysql/
7、编辑my.cnf,添加配置文件,配置内容为
[root@localhost local]# vi /usr/local/mysql/my.cnf
[client]
#password=88888888 socket=/usr/local/mysql/mysql.sock [mysql]socket=/usr/local/mysql/mysql.sock# 设置mysql客户端默认字符集default-character-set=utf8[mysqld]
pid-file=/usr/local/mysql/mysqld.pid log-error = /usr/local/mysql/log/mysql-error.log #设置3306端口port = 3306 # 设置mysql的安装目录basedir=/usr/local/mysql# 设置mysql数据库的数据的存放目录datadir=/usr/local/mysql/data#socksocket=/usr/local/mysql/mysql.sock# 允许最大连接数max_connections=200# 服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8mb4# 创建新表时将使用的默认存储引擎default-storage-engine=INNODB#允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE)
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION#ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION#解决mysql连接慢(201906181517)
skip-name-resolve#skip-grant-tables ---------这行可以不加,慎重使用,
8、编译安装并初始化mysql,记住命令行末尾的密码:
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql 2017-08-31T08:50:23.910440Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-08-31T08:50:23.910635Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' con figuration directive.2017-08-31T08:50:24.709286Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-08-31T08:50:24.767540Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-08-31T08:50:24.892629Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6e083b8f-8e29-11e7-88b1- 005056b427be.2017-08-31T08:50:24.895674Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-08-31T08:50:24.896645Z 1 [Note] A temporary password is generated for root@localhost: gFamcspKm2+u
9、启动mysql服务
10、做个软连接,重启服务
[root@localhost local]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql [root@localhost local]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
11、做个软链接,将安装目录下的mysql 放在/usr/bin 目录下
[root@localhost local]# ln -s /usr/local/mysql/bin/mysql /usr/bin
12、登录msyql,输入密码(密码为步骤7初始化生成的密码)
[root@localhost local]# mysql -u root -p Enter password:
13、修改密码并开放远程
msql>alter user 'root'@'localhost' identified by '123456';mysql>use mysql;msyql>update user set user.Host='%' where user.User='root';mysql>flush privileges;mysql>quit
14、设置开机自启动
1、将服务文件拷贝到init.d下,并重命名为mysql[root@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld2、赋予可执行权限[root@localhost local]# chmod +x /etc/init.d/mysqld3、添加服务[root@localhost local]# chkconfig --add mysqld4、显示服务列表[root@localhost local]# chkconfig --list5、重启服务器(一般不用重启,所以此步略掉!!!)[root@localhost local]# reboot