mysql5.7在centos上安装的完整教程以及相关的“坑”

安装前的准备


Step1: 如果你系统已经有mysql,如一般centos自带mysql5.1系列,那么你需要删除它,先检查一下系统是否自带mysql



[plain]  view plain  copy
  1. yum list installed | grep mysql  


Step2: 删除系统自带的mysql及其依赖命令


[plain]  view plain  copy
  1. yum -y remove mysql-libs.x86_64  


Step3: 给CentOS添加rpm源,并且选择较新的源命令


[plain]  view plain  copy
  1. wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm  
  2. yum localinstall mysql-community-release-el6-5.noarch.rpm  
  3. yum repolist all | grep mysql  
  4. yum-config-manager --disable mysql55-community  
  5. yum-config-manager --disable mysql56-community  
  6. yum-config-manager --enable mysql57-community-dmr  
  7. yum repolist enabled | grep mysql  

开始安装


Step4:安装mysql 服务器命令


[plain]  view plain  copy
  1. yum install mysql-community-server  

CENTOS7上安装MYSQL5.7还有一个巨坑


之前的Linux体系中数据库大局部是mysql,不外自从被sun收买以后,便出用散成正在centos那些开源Linux体系中了,那末若是念用的话便须要本身装置了,起首centos7 已没有支撑mysql。


以前的Linux系统中数据库大部分是mysql,不过自从被sun收购之后,就没用集成在centos这些开源Linux系统中了,那么如果想用的话就需要自己安装了,首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以在运行以下命令前:


[plain]  view plain  copy
  1. yum install mysql-community-server  

需要先卸载掉mariadb,以下为卸载mariadb步骤

[plain]  view plain  copy
  1. rpm -qa | grep mariadb  

当检查出了系统自带的mariadb后如版本为:mariadb-libs-5.5.37-1.el7_0.x86_64 那么使用以下命令:

[plain]  view plain  copy
  1. rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64  

强制卸了它,再安装mysql5.7即可。

Step5: 启动mysql命令


[plain]  view plain  copy
  1. service mysqld start  



Step6: 查看mysql是否自启动,并且设置开启自启动命令


[plain]  view plain  copy
  1. chkconfig --list | grep mysqld  
  2. chkconfig mysqld on  



mysql5.7安装完后如何开启远程root包括远程用户权限



mysql5.7对于安全模块进行了升级,因此如果你想像以前那样在安装完mysql后直接以mysql -u root登录进去再通过一系列的sql命令来更改权限但是这在mysql5.7上是行不通的,按照以前的做法,你会在面临mysql5.7碰到这样的一个报错“access denied for user root@localhost” ,因此请按照以下使用说明操作。


Step1: 停止mysqld服务并使用mysqld safe启动


[plain]  view plain  copy
  1. service mysqld stop  
  2. mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  

RHEL7.0系列的发行版(例如CentOs 7),特征是使用了systemd来代替原有的init,作为第一支启动的程序。此时网络上面所说的mysqld_secure已经不可使用。但是查看官方文档后,得知在这种情况下mysqld可以支持部分mysqld_safe的参数,命令如下:


[plain]  view plain  copy
  1. mysqld   --user=mysql --skip-grant-tables --skip-networking &  


Step2:登录mysql


此时,你在mysql服务器上使用


[plain]  view plain  copy
  1. mysql -uroot -p  


就可以登录mysql了


Step3: 更改mysql安全密码


先説一下原因,mysql5.7出现这样的问题,是因为MYSQL5.6之后,加强了对安全性的管控,认为root用户进行mysql操作是一种危险的行为,于是限制了root用户登录mysql()。但是我们可以通过修改Mysql中user表的方法解决该问题
(网络上还有一种做法是查看/var/log/mysql.log,该文件内有安装后Mysql生成的随机密码,然后用文件里的密码正常登录即可,有兴趣者自己可以试下,此处使用正规操作步骤)


[sql]  view plain  copy
  1. mysql> SET PASSWORD = PASSWORD('ur password here');  

如果出现以下信息:

[plain]  view plain  copy
  1. ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement   


请先运行

[plain]  view plain  copy
  1. update mysql.user set authentication_string=password('newpassword') where user='root'  



Step4:更改mysql root的密码(和Step3中保持一致)

[sql]  view plain  copy
  1. update mysql.user set authentication_string=password('newpassword'where user='root'  




之前的mysql版本为:


[sql]  view plain  copy
  1. UPDATE user SET Password=PASSWORD('newpassword'where USER='root';  
  2. flush privileges;  




而mysql5.7已经把PASSWORD字段改名成了"authentication_string"这个名字了,此处需要注意了。


Step5:建立可供远程连接的root用户

[sql]  view plain  copy
  1. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ur password here' WITH GRANT OPTION;  



Step6:在远程装个mysql workbench然后用远程root登录,爱干吗干吗吧


MYSQL核心配置文件示例



虚拟CPU 6C
内存:6GB
优化过的配置如下:

[plain]  view plain  copy
  1. # For advice on how to change settings please see  
  2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html  
  3.   
  4.   
  5. [mysqld]  
  6. #  
  7. # Remove leading # and set to the amount of RAM for the most important data  
  8. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.  
  9. # innodb_buffer_pool_size = 128M  
  10. #  
  11. # Remove leading # to turn on a very important data integrity option: logging  
  12. # changes to the binary log between backups.  
  13. # log_bin  
  14. #  
  15. # Remove leading # to set options mainly useful for reporting servers.  
  16. # The server defaults are faster for transactions and fast SELECTs.  
  17. # Adjust sizes as needed, experiment to find the optimal values.  
  18.   
  19.   
  20. join_buffer_size = 128M  
  21. sort_buffer_size = 6M  
  22. read_rnd_buffer_size = 4M  
  23.   
  24.   
  25. #deprecate this option after mysql5.5 default-character-set = utf8  
  26.   
  27.   
  28. character-set-server=utf8  
  29. open_files_limit    = 10240  
  30. back_log = 384  
  31. max_connections = 500  
  32. #deprecate this option after mysql5.5 table_cache = 512K  
  33. max_allowed_packet =16M  
  34. query_cache_size = 384M  
  35. table_open_cache = 512   
  36. key_buffer_size = 384M   
  37.   
  38.   
  39. datadir=/var/lib/mysql  
  40. socket=/var/lib/mysql/mysql.sock  
  41.   
  42.   
  43. # Disabling symbolic-links is recommended to prevent assorted security risks  
  44. symbolic-links=0  
  45.   
  46.   
  47. log-error=/var/log/mysqld.log  
  48. pid-file=/var/run/mysqld/mysqld.pid  
  49.   
  50.   
  51. slow_query_log_file = /var/log/mysqld-slow-query.log    
  52. log-short-format  
  53. long-query-time = 3    
  54. #log-long-format    
  55. #log-slow-admin-statements    
  56. log-queries-not-using-indexes  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值