CentOS 7 下使用yum安装MySQL5.7.24

本文介绍了在CentOS 7系统下,如何通过yum来安装MySQL5.7.24。首先,卸载旧版本的MySQL,然后下载并安装MySQL的repo源,接着安装mysql-server,启动服务并重置root用户的密码。最后,配置允许远程登录和修改字符集为utf8。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CentOS 7 下使用yum安装MySQL5.7.24

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

1.卸载  先停掉mysql进程   没有安装过的可以直接跳过
  [root@centos7 ~]# netstat -plntu
  [root@centos7 ~]# pkill -9 mysqld
  //查询安装情况
  [root@centos7 ~]# rpm -qa|grep -i mysql
  //卸载旧版本
  [root@centos7 ~]# yum -y remove mysql-community-client-5.6.38-2.el7.x86_64
  //卸载不掉的用 rpm -ev 依次卸载 直到没有
  
2.下载mysql的repo源 这个安装的mysql5.7.24
  //进入local目录并新建
  [root@centos7 ~]# cd /usr/local/
  [root@centos7 local]# mkdir mysql
  [root@centos7 local]# cd mysql
  //下载文件包
  [root@centos7 mysql]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
  //安装包
  [root@centos7 mysql]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
  //安装mysql-server 安装路径是默认的。
  [root@centos7 mysql]# yum -y install mysql-server

  //默认配置文件路径: 
  //配置文件:/etc/my.cnf 
  //日志文件:/var/log/var/log/mysqld.log 
  //服务启动脚本:/usr/lib/systemd/system/mysqld.service 
  
3.启动mysql服务
  [root@centos7 ~]# service mysqld restart
  //重置密码
  [root@centos7 ~]# grep "password" /var/log/mysqld.log
  2018-12-19T11:00:36.524270Z 1 [Note] A temporary password is generated for root@localhost: t2w5hj3xhx>Y
  //使用上面随机密码登录
  [root@centos7 ~]# mysql -u root -p
  Enter password:   //输入上面的密码t2w5hj3xhx>Y
  //第一次登陆 ,需要设置新密码 要不什么也不能操作
  mysql> select version();
  ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  //密码太简单不能修改
  mysql> SET PASSWORD = PASSWORD('123456');
  ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
  //这样就成功了。
  mysql> SET PASSWORD = PASSWORD('YiZhan@1688');
  Query OK, 0 rows affected, 1 warning (0.00 sec)

-------到此,Mysql就安装好了。

4.开通远程登录
  (1)、本地登录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 'YiZhan@1688' with grant option;
     grant all privileges on *.* to 'root'@'%' identified by'TangKa@1688' with grant option;

  (2).执行以下这个,FLUSH PRIVILEGES; 不然可能会有问题. 

  (3).重启mysql, service mysqld restart. 

-------到此,可以远程访问了。

5.修改字符集编码为utf8
  (1)、vim /etc/my.cnf 内容为:
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
init_connect = 'SET NAMES utf8'
collation-server=utf8_general_ci

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
default-character-set=utf8

grant all privileges on *.* to 'root'@'%' identified by'TangKa@1688' with grant option;

//修改root用户密码
use mysql;
update user set password=password('admin') where user = 'root';
flush PRIVILEGES;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值