centos7安装MySQL数据库
MySQL5.7安装
下载安装MySQL官方库
下载rpm包
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
安装包
yum install mysql57-community-release-el7-10.noarch.rpm -y
安装数据库,跳过检查
yum install mysql-community-server --nogpgcheck -y
数据库基本操作配置
启动数据库
systemctl start mysqld.service
查看启动状态,启动正常应显示running
systemctl status mysqld.service
获取MySQL的root用户密码
grep "password" /var/log/mysqld.log
使用获取到的密码登录MySQL
mysql -uroot -p
第一步需修改密码,不然无法执行任何操作,将new password改为自己的新密码,可以使用随机密码生成器来生成密码,
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
开启远程访问权限
grant all privileges on \*.* to 'root'@'%' identified by 'password' with grant option;
刷新权限
flush privileges;
修改默认语言为utf-8,编辑配置文件
vim /etc/my.cnf
新增以下配置
character-set-server=utf-8;
重启MySQL
systemctl restart mysqld.service
MySQL8.0安装
安装Mysql8.0 的yum资源库
下载安装rpm包
yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
更新yum源
yum clean all
yum makecache
查看所有可用版本
yum repolist all | grep mysql
#输出如下,可以看到8.0的状态为enable
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 199
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 92
mysql-tools-community-source MySQL Tools Community - Sour disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 346
mysql80-community-source MySQL 8.0 Community Server - disabled
安装MySQL8.0
跳过证书检查安装
yum install mysql-community-server --nogpgcheck -y
启动MySQL以及设置开启自启动
systemctl start mysqld.service
systemctl enable mysqld.service
基本配置
和5.7的安装差不多
获取初始密码
cat /var/log/mysqld.log | grep password
输出如下,最后即为默认密码
2022-09-07T01:28:47.037660Z 6 [Note] [MY-010454] [Server] A temporary password is generated ``for` `root@localhost: uiXTtjyU``/5Pu
修改密码
ALTER USER "root"@"localhost" IDENTIFIED BY "PASSWORD";
设置远程登录
update mysql.user set host='%' where user="root";
flush privileges;