博主的服务器是Centos 7.2 64位,wget都没有
一、准备和卸载
检查wget、vim是否安装,如果没有执行以下命令
yum -y install wget
检查是否存在MySQL,卸载方法网上一堆,自行谷歌百度,我卸载如下
二、安装
1、在线下载压缩包,需要等一会儿
[root@localhost /]# cd usr/local/
[root@localhost local]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
2、解压
[root@localhost local]# tar -xzvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
稍微等待下
3、修改文件夹名字
[root@localhost local]# mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql
4、检查并创建用户和用户组
出现类似下面的就不需要创建了
[root@localhost local]# cat /etc/group | grep mysql
mysql:x:1000:
[root@localhost local]# cat /etc/passwd | grep mysql
mysql:x:1000:1000::/home/mysql:/bin/bash
[root@localhost local]#
否则执行 注: -r参数表示mysql用户是系统用户,不可用于登录系统
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -r -g mysql mysql
5、创建data文件夹
5.7.28版本是没有data文件夹的
[root@localhost local]mkdir /usr/local/mysql/data
6、授权目录和用户
很重要的一步,特别重要
[root@localhost /]# cd /usr/local/
[root@localhost local]# chown -R mysql:mysql mysql/
[root@localhost local]# chmod -R 755 mysql/
7、安装和初始化
执行下面之前去/etc/目录下查看是否有my.cnf配置文件,如果有,删除或者修改名字备份起来!不然会出现各种PID或者SOCK有关的问题
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
执行完成之后
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2019-12-18T16:38:20.300936Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-18T16:38:21.037889Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-07-18T16:38:21.124063Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-07-18T16:38:21.194242Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been start ed. Generating a new UUID: df9bf1ac-b410-46b3-9208-a0dc663052a1.
2019-07-18T16:38:21.195622Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-07-18T16:38:21.196412Z 1 [Note] A temporary password is generated for root@localhost: em)dbUhDl3))
如果没有error就是顺利的,如果按照我的步骤来是不会出现问题的;最后一行会有默认生成的密码,记下来,后面要用
8、复制启动脚本到资源目录
[root@localhost local]# cd mysql
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
9、增加mysqld服务控制脚本权限
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
10、将mysqld服务加入到系统服务
[root@localhost mysql]# chkconfig --add mysqld
11、添加mysql命令
[root@localhost mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin
12、启动mysql
[root@localhost mysql]# service mysqld start
到现在基本99%会显示SUCCESS
13、登录mysql
[root@localhost mysql]# mysql -uroot -p
Enter password:
输入刚才的临时密码
14、修改密码
mysql> flush privileges;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
mysql> flush privileges;
mysql> quit
[root@localhost mysql]# mysql -uroot -p
15、防火墙开放端口(如果需要的话)
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
16、软件连接
如果出现这样的报错
执行
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
mysql> flush privileges;
然后再次测试,连接上了。