Centos7二进制安装Mysql5.7
1.创建mysql用户组和用户
groupadd mysql
useradd -r -g mysql -s /sbin/nolog mysql
2.下载mysql相关版本二进制包,并解压移动至/usr/local目录
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz #解压到当前目录 mv /usr/local/src/mysql-5.7.24-linux-glibc2.12-x86_64/ /usr/local/mysql #移动并重命名
3.在Mysql目录创建data目录,并授予相关权限
mkdir -p /usr/local/mysql/ {log,data} chown -R mysql.mysql /usr/local/mysql chmod -R 755 /usr/local/mysql
4.卸载自带mysql、mariadb数据
rpm -qa | grep mysql rpm -qa | grep mariadb rpm -e --nodeps 包名
5.初始化mysql数据库,会生成一个随机密码,记得保存好。警告提示关系不大,可以忽略
[root@oracle mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 2018-11-14T09:05:32.752289Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-11-14T09:05:34.248738Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-11-14T09:05:34.787689Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-11-14T09:05:34.941610Z 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: 7238b05b-e7ec-11e8-b680-3417ebcfddea. 2018-11-14T09:05:34.980838Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-11-14T09:05:34.981293Z 1 [Note] A temporary password is generated for root@localhost: Lk5jgsJ2nG#7
6.配置/etc/my.cnf文件,至关重要。数据库能不能正常启动就看这个配置文件了。如果配置不对,会给你搞一堆的错误出来....很是脑阔痛.
注意:不存的在目录一定要手动建好,不然启动Mysql服务会报错,切记。后缀为.err的文件需要手工创建
[mysql] default-character-set=utf8 socket=/tmp/mysql.sock [mysqld] port=3306 basedir=/usr/local/mysql datadir=/usr/local/mysql/data character-set-server=utf8 default_storage_engine = InnoDB innodb_buffer_pool_size=200M max_allowed_packet=16M explicit_defaults_for_timestamp=1 log-output=FILE general_log=0 general_log_file=/usrl/local/mysql/log/mysql-general.log slow_query_log=ON slow_query_log_file=/usr/local/mysql/log/mysql-query.log long_query_time=10 log-error=/usr/local/log/mysql-error.log user=mysql
7.启动mysql数据库
ln -vs /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #建立软连接
/etc/init.d/mysqld start
注意:如果你的mysql不是按照我这个目录来安装配置的,请把/etc/init.d/mysqld这个文件里面的路径修改为你的路径,不然数据库起不来,跟你路径不匹配的都要改掉
basedir= datadir= bindir= ....
8.登陆数据库
ln -vs /usr/local/mysql/bin/mysql /usr/bin/ #建立软链接,也就是windows说的快捷方式
mysql -uroot -p密码 #用初始化生产的随机密码登陆数据库做相应的授权操作
附加
总结一下二进制安装Mysql5.7数据库所遇到的问题
1.Cetos7操作系统不能解压带gz后缀的包,换了多少个参数都没用。不知道是哪里的问题,暂时未找到解决办法,有遇到的网友可以留言告知下。错误如下所示
gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
2.前面也说到配置文件的问题,这个真的是至关重要,就因为配置文件里面有个两个datadir导致一直出现如下错误,如果mysql.sock之前已经存在了请删除在启动Mysql,不然也会报下面的错误
[root@oracle data]# /etc/init.d/mysqld start Starting MySQL..... ERROR! The server quit without updating PID file (/var/lib/mysql/oracle.pid).
3.登陆数据库之后出现的问题,如下所示
mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
这个问题这个主要是由一个参数控制的 default_password_lifetime,有兴趣的朋友可以去看看官方的解释
我是从一个博客中看到这个的。资料来源
解决方法如下
alter user 'root'@'localhost' identified by "密码";
flush privileges
4.mysql -uroot -p不能使用,这个是由于没有建立软链接导致;上文有说。
大概就这么多,如有遗漏和不足请大家留言,我会及时更正文档!