mysql版本:mysql-5.7.24
本例mysql下载地址:
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
执行以下命令后,将会把文件下载到当前目录
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
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组和用户是否存在,如无创建:
[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd |grep mysql
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
4、从官网下载mysql安装包,解压后移动到/usr/local/mysql下
1 |
|
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、编译安装并初始化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
8、启动mysql服务
[root@localhost local]# /usr/local/mysql/support-files/mysql.server start
9、做个软连接,重启服务
[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!
10、做个软链接,将安装目录下的mysql 放在/usr/bin 目录下
[root@localhost local]# ln -s /usr/local/mysql/bin/mysql /usr/bin
11、登录msyql,输入密码(密码为步骤7初始化生成的密码)
[root@localhost local]# mysql -u root -p Enter password:
12、修改密码并开放远程
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
13、编辑my.cnf,添加配置文件,配置内容为
[root@localhost local]# vi /usr/local/mysql/my.cnf [mysqld] port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
14、设置开机自启动
1、将服务文件拷贝到init.d下,并重命名为mysql [root@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 2、赋予可执行权限 [root@localhost local]# chmod +x /etc/init.d/mysqld 3、添加服务 [root@localhost local]# chkconfig --add mysqld 4、显示服务列表 [root@localhost local]# chkconfig --list 5、重启服务器 [root@localhost local]# reboot
分类: Linux