Centos 7 解压安装mysql5.7

前端之家收集整理的这篇文章主要介绍了Centos 7 解压安装mysql5.7前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
之前在各大论坛上看到有很多相关介绍,但是总觉得自己安装的时候有些问题,所以这一篇借鉴 博客园-大大的橙子,但是,他的文章中安装过程中有有点问题,所以在其基础上进行了修修补补,所以目前本人经过多次裸机安装,亲测正常。

卸载系统自带的Mariadb

  1. [root@aliyun ~]# rpm -qa|grep mariadb
  2. mariadb-libs-5.5.44-2.el7.centos.x86_64
  3. [root@aliyun ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
删除etc目录下的my.cnf文件
  1. [root@aliyun ~]# rm /etc/my.cnf
  2. rm: cannot remove ?etc/my.cnf? No such file or directory

检查MysqL是否存在

  1. [root@aliyun ~]# rpm -qa | grep MysqL
  2. [root@aliyun ~]#

安装必要软件

  1. [root@aliyun ~]# yum install -y libaio

检查MysqL组和用户是否存在,如无创建

  1. [root@aliyun ~]# cat /etc/group | grep MysqL
  2. [root@aliyun ~]# cat /etc/passwd | grep MysqL

创建MysqL用户

  1. [root@aliyun ~]# groupadd MysqL

创建一个用户名MysqL用户并加入MysqL用户

  1. [root@aliyun ~]# useradd -g MysqL MysqL

制定password 为111111

  1. [root@aliyun ~]# passwd MysqL
  2. Changing password for user MysqL.
  3. New password:
  4. BAD PASSWORD: The password is a palindrome
  5. Retype new password:
  6. passwd: all authentication tokens updated successfully.

由于我的/usr/local空间不足,所以我安装到/var

  1. [root@aliyun var]# tar -zxvf MysqL-5.7.18-linux-glibc2.5-x86_64.tar.gz
  2. [root@aliyun var]# mv MysqL-5.7.18-linux-glibc2.5-x86_64/ MysqL57

更改所属的组和用户

  1. [root@aliyun var]# chown -R MysqL MysqL57/
  2. [root@aliyun var]# chgrp -R MysqL MysqL57/
  3. [root@aliyun var]# cd MysqL57/
  4.  
  5. [root@aliyun MysqL57]# mkdir data
  6.  
  7. [root@aliyun MysqL57]# chown -R MysqL:MysqL data

配置my.cnf

  1. [MysqL]
  2. # 设置MysqL客户端默认字符集
  3. default-character-set=utf8
  4. [MysqLd]
  5. skip-name-resolve
  6. #设置3306端口
  7. port = 3306
  8. # 设置MysqL的安装目录
  9. basedir=/var/MysqL57
  10. # 设置MysqL数据库的数据的存放目录
  11. datadir=/var/MysqL57/data
  12. # 允许最大连接数
  13. max_connections=200
  14. # 服务端使用的字符集默认为8比特编码的latin1字符集
  15. character-set-server=utf8
  16. # 创建新表时将使用的默认存储引擎
  17. default-storage-engine=INNODB
  18. lower_case_table_names=1
  19. max_allowed_packet=16M

开始初始化安装,注意里面的数据库密码,请暂时先保存下来,是初始化密码,登陆后再修改

  1. shell> bin/MysqLd --initialize --user=MysqL --basedir=/var/MysqL57/ --datadir=/var/MysqL57/data/
  2. 2018-01-31T14:15:21.160016Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  3. 2018-01-31T14:15:25.102080Z 0 [Warning] InnoDB: New log files created,LSN=45790
  4. 2018-01-31T14:15:25.537811Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  5. 2018-01-31T14:15:25.646880Z 0 [Warning] Failed to setup SSL
  6. 2018-01-31T14:15:25.716100Z 0 [Warning] SSL error: SSL context is not usable without certificate and private key
  7. 2018-01-31T18:14:25.716295Z 1 [Warning] A temporary password is generated for root@localhost: rq/Dldw^lkdfd
  8.  
  9. [root@aliyun MysqL57]# cp ./support-files/MysqL.server /etc/init.d/MysqLd
  10. [root@aliyun MysqL57]# chown 777 /etc/my.cnf
  11. [root@aliyun MysqL57]# chmod +x /etc/init.d/MysqLd
  12.  
  13. [root@aliyun MysqL57]# /etc/init.d/MysqLd restart
  14. Shutting down MysqL.. SUCCESS!
  15. Starting MysqL. SUCCESS!

设置开机启动

  1. [root@aliyun MysqL57]# chkconfig --level 35 MysqLd on
  2. [root@aliyun MysqL57]# chkconfig --list MysqLd
  3.  
  4. [root@aliyun MysqL57]# chmod +x /etc/rc.d/init.d/MysqLd
  5. [root@aliyun MysqL57]# chkconfig --add MysqLd
  6. [root@aliyun MysqL57]# chkconfig --list MysqLd
  7. [root@aliyun MysqL57]# service MysqLd status
  8. SUCCESS! MysqL running (4475)

设置/etc/profile环境 在尾部添加

  1. export PATH=$PATH:/var/MysqL57/bin

执行source 使配置文件生效

  1. [root@aliyun MysqL57]# source /etc/profile

使用初始密码,进行连接数据库

  1. [root@aliyun bin]# MysqL -uroot -p
  2. Enter password:
  3. Welcome to the MysqL monitor. Commands end with ; or \g.
  4. Your MysqL connection id is 5
  5. Server version: 5.7.18
  6.  
  7. Copyright (c) 2000,2017,Oracle and/or its affiliates. All rights reserved.
  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12.  
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  14. #修改密码为 111111
  15. MysqL> set PASSWORD = PASSWORD('111111');
  16. Query OK,0 rows affected,1 warning (0.00 sec)
  17.  
  18. MysqL> flush privileges;
  19. Query OK,0 rows affected (0.01 sec)
  20.  
  21. #添加远程访问权限
  22. MysqL> use MysqL
  23. Reading table information for completion of table and column names
  24. You can turn off this feature to get a quicker startup with -A
  25.  
  26. Database changed
  27.  
  28. MysqL> update user set host='%' where user='root';
  29. Query OK,1 row affected (0.00 sec)
  30. Rows matched: 1 Changed: 1 Warnings: 0
  31.  
  32. MysqL> select host,user from user;
  33. +-----------+-----------+
  34. | host | user |
  35. +-----------+-----------+
  36. | % | root |
  37. | localhost | MysqL.sys |
  38. +-----------+-----------+
  39. rows in set (0.00 sec)
  40.  
  41.  
  42. create user 'xxx'@'%' identified by '123'; 这里 @‘%’ 表示在任何主机都可以登录

重启生效

  1. [root@aliyun bin]# /etc/init.d/MysqLd restart
  2. Shutting down MysqL.. SUCCESS!
  3. Starting MysqL. SUCCESS!

设置任何目录下都可以使用MysqL命令

  1. ln -s /var/MysqL57/bin/MysqL /usr/bin/MysqL

猜你在找的CentOS相关文章