CentOS 7 下使用yum安装MySQL5.7.20

CentOS7默认数据库是mariadb, 可是 好多用的都是mysql ,可是CentOS7的yum源中默认好像是没有mysql的。java

1.卸载  先停掉mysql进程   没有安装过的能够直接跳过mysql

       

pkill -9 mysqld

rpm -qa|grep -i mysql  

yum -y remove  

yum -y remove mysql-community-client-5.6.38-2.el7.x86_64   //卸载不掉的用 rpm -ev 重复屡次 

      

2.下载mysql的repo源 这个安装的mysql5.7.20  /**纠正一下,这源下载的是最新的版本  ****/sql

   [root@localhost ~]# cd /usr/local/src/
   [root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 数据库

   [root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm vim

   [root@localhost src]#  yum -y install mysql-server 安全

(也能够指定安装目录     yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server  )我没试,这样装环境变量配置都不用你管,装上直接启动就行。安装路径是默认的。socket

    

   一路 y tcp

 

根据步骤安装就能够了,ide

默认配置文件路径: 
配置文件:/etc/my.cnf 
日志文件:/var/log/var/log/mysqld.log 
服务启动脚本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid.net

 

  配置  my.cnf        vim /etc/my.cnf

  1. [mysqld]
  2. #
  3. # Remove leading # and set to the amount of RAM for the most important data
  4. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  5. # innodb_buffer_pool_size = 128M
  6. #
  7. # Remove leading # to turn on a very important data integrity option: logging
  8. # changes to the binary log between backups.
  9. # log_bin
  10. #
  11. # Remove leading # to set options mainly useful for reporting servers.
  12. # The server defaults are faster for transactions and fast SELECTs.
  13. # Adjust sizes as needed, experiment to find the optimal values.
  14. # join_buffer_size = 128M
  15. # sort_buffer_size = 2M
  16. # read_rnd_buffer_size = 2M
  17. datadir=/var/lib/mysql
  18. socket=/var/lib/mysql/mysql.sock
  19. server_id = 1
  20. expire_logs_days = 3
  21.  
  22. # Disabling symbolic-links is recommended to prevent assorted security risks
  23. symbolic-links=0
  24.  
  25. log-error=/var/log/mysqld.log
  26. pid-file=/var/run/mysqld/mysqld.pid

 

不过安装完成后,密码为随机密码,须要重置密码。

 

4.  启动mysql服务

service mysqld restart

 重置密码

    [root@localhost ~]# grep "password" /var/log/mysqld.log    

    

    能够看到  输入 mysql -u root -p   密码 进入      第一次登录 ,须要重置密码 要不什么也不能操做 

        

       接下来重置密码:5.7.20 为了安全密码           必须包含 数字字母符号

      踩过的坑啊,设置了好几回。还有这ip不能是% 不知道为何  反正第一次设置成%没成功  登上去以后再改就能够改了。

       把密码改简单的方法 http://blog.csdn.net/z13615480737/article/details/78907697

      alter user 'root'@'localhost' identified by 'Root!!2018';  

 

     最后记得刷新权限;

     flush privileges 

    也能够 直接再添加新用户     

   

 

 

1. iptables放开3306端口

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

/etc/rc.d/init.d/iptables save

2.本地登陆mysql,在'mysql'这个数据库里执行GRANT ALL ON *.* to user@'IP' IDENTIFIED BY 'password';  其中,user表示用户,对我来讲就是root,IP表示登陆机器的ip,因为个人电脑是DHCP,就直接写了个通配符%. password该用户对应的密码. 

因此个人命令就是grant all privileges on *.* to 'root'@'%' identified by '*****' with grant option;

增长root用户指定能够任意IP登陆,若是想限制只能让指定IP登陆请把%替换成IP地址

 

3.执行如下这个,FLUSH PRIVILEGES; 否则可能会有问题. 

4.重启mysql, service mysqld restart. 

 

 

   

 

   问题:若是发现找不到密码!!!!!

   解决:只能经过忘记密码的方式修改密码!!! 在安装的过程当中发现找不到密码???折腾了好长时间 经过修改密码找回以后发现、原来以前安装的数据库在了,就没有生产新的数据库!!用的仍是以前的配置。

2.看mysql启动了没?初始化数据库了没?  通常直接启动 数据库 就能够 用grep "password" /var/log/mysqld.log    看到随机密码了

 

修改MySQL的登陆设置:

#vi /etc/my.cnf

在[mysqld]的段中加上一句:skip-grant-tables 保存而且退出vi。

从新启动mysqld

从新启动mysqld #/etc/init.d/mysqld restart ( service mysqld restart ) use mysql  update user set password=password("12345") where user="root"; mysql 5.7的数据库没有了password字段 用的是authentication_string字段 mysql> update mysql.user set authentication_string=password('root') where user='root' ; flush privileges; 修改密码以后在改回来

相关文章
相关标签/搜索