概述
1.下载并安装MySQL官方的 Yum Repository
#从官方获取RPM包;get后的rpm文件路径需从MySQL官网获取 #从官网获取推荐系统,非推荐系统可能导致安装失败 wget -i -c http://dev.mysql.com/get/mysql80-community-release-el8-2.noarch.rpm #安装RPM包 yum -y install mysql80-community-release-el8-2.noarch.rpm
2.安装MySQL-server
yum -y install mysql-community-server
3.启动MySQL-server
启动命令:systemctl start mysqld
未启动状态如下:
[root@VM-0-13-centos emqx]# systemctl status mysqld ● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: inactive (dead)
启动状态如下:
[root@VM-0-13-centos emqx]# systemctl status mysqld ● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2021-10-28 15:37:50 CST; 12s ago Process: 56130 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 55989 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS) Process: 55965 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 56081 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 11438) Memory: 449.2M CGroup: /system.slice/mysqld.service └─56081 /usr/libexec/mysqld --basedir=/usr
4.登录并修改root账号密码
#首次登陆(无需密码) mysql -uroot #选择数据库 use mysql #修改root账户密码 ALTER USER 'root' @'localhost' IDENTIFIED BY '密码'; ALTER USER 'root' @'localhost' IDENTIFIED BY 'Yimiiot@123'; #刷新权限表 flush privileges; #退出后重新登录 mysql -uroot -p
4.开放远程登录权限
#同样还是先登陆mysql,这时登陆记得用我们新设置的密码。
mysql -uroot -p
#登陆成功后用 show databases; 来显示所有的数据库
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
use mysql; 来更改管理员信息
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
select user,host from user; 查询所有的管理员
mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 4 rows in set (0.00 sec)
update user set host = '%' where user = 'root'; 更新root用户的本地访问为% ,即代表可以远程访问。通常情况下我们的root用户应该只能本地访问,但是我们今天是为了学习方便,所以就设置root可以远程访问了。
mysql> update user set host = '%' where user = 'root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0
flush privileges;刷新下权限。
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
select user,host from user; 查询所有的管理员,root后面的信息就改变了。
mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | root | % | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | +------------------+-----------+ 4 rows in set (0.00 sec)
5.数据库导入
查看所有数据库
mysql> show databases; +--------------------+ | Database | +--------------------+ | Test | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
切换到要导入的数据库
mysql> use Test; Database changed
# mysql> source /opt/cs_20211027_233857.sql
最后
以上就是小巧花瓣为你收集整理的CentOS8安装MySQL8(Yum安装)的全部内容,希望文章能够帮你解决CentOS8安装MySQL8(Yum安装)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复