Centos7中yum安装MySQL

时间:2023-02-03 22:22:37
  1. 安装mysql

    [root@localhost ~]# yum update
    [root@localhost ~]# cat /etc/redhat-release
    CentOS Linux release 7.4. (Core)
    [root@localhost ~]# yum install mysql
    [root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
    [root@localhost ~]# rpm -ivh mysql-community-release-el7-.noarch.rpm
    [root@localhost ~]# yum install mysql-community-server
    [root@localhost ~]# yum install mysql-devel
    [root@localhost ~]# service mysqld restart
  2. 配置MySQL

安装成功后重启MySQL服务

初次安装mysql,root账户没有密码,设置root密码

[root@localhost ~]# mysql -u root
mysql> set password for 'root'@'localhost' =password('password');

注:root为数据库账号,password为数据库密码。

开启MySQL远程连接

mysql> GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> flush privileges;