安装官方Yum参库
[root@localhost]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
安装必要的配置文件包
[root@localhost]# yum -y install mysql57-community-release-el7-10.noarch.rpm
安装MySQL服务
[root@localhost]# yum -y install mysql-community-server
启动MySQL服务
[root@localhost]# systemctl start mysqld.service
[root@localhost]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-08-18 01:03:31 CST; 13s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 26880 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 26826 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 26883 (mysqld)
Memory: 322.6M
CGroup: /system.slice/mysqld.service
└─26883 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Aug 18 01:03:27 chanfu-dev-104-103 systemd[1]: Starting MySQL Server...
Aug 18 01:03:31 chanfu-dev-104-103 systemd[1]: Started MySQL Server.
查看初始密码,MySQL启动的时候会自动生成一个初始密码
[root@localhost]# grep "password" /var/log/mysqld.log
2021-08-17T17:03:29.580463Z 1 [Note] A temporary password is generated for root@localhost: )wMd1jSybZj;
使用初始密码进入MySQL命令行
[root@localhost]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35
MySQL将强制要求修改初始密码,否则无法进行其它操作
mysql> alter user 'root'@'localhost' identified by '填入你的密码';
Query OK, 0 rows affected (0.01 sec)
给root用户授权并允许远程连接
mysql> grant all privileges on *.* to 'root'@'%' identified by '填入你的密码,同上' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
使用root 和 Navicat客户端连接服务器并创建数据库
创建一个开发用户并授权
-- 创建用户
CREATE USER 'dev_admin'@'%' identified BY 'xxxyyy';
-- 授权
GRANT select, insert, update, delete, alter, create, execute, trigger, index ON yearning.* TO 'dev_admin'@'%';
FLUSH PRIVILEGES;
结束