安装MySQL
安装Mysql (CentOS 8.5)
1. 下载并安装 MySQL 官方的 Yum Repository
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
2、然后进行repo的安装:
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum install mysql-server
3.MySQL数据库设置
1. 设置不区分大小写
vim /etc/my.cnf
在[mysqld]下,添加以下内容
#让MYSQL大小写敏感(1-不敏感,0-敏感)
lower_case_table_names=1
2. 启动MySQL
systemctl start mysqld.service
3. 查看MySQL运行状态
systemctl status mysqld.service
4.设置密码
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
grep "password" /var/log/mysql/mysqld.log
如果提示为空按下enter就进入数据库,否则输入得到的默认密码
进入数据库:
mysql -uroot -p
修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
4.设置远程访问
1.开放3306端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp
如果提示FirewallD is not running
通过systemctl status firewalld查看firewalld状态,发现当前是dead状态,即防火墙未开启。
通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。
再次通过systemctl status firewalld查看firewalld状态,显示running即已开启了。
然后再执行语句。
如果要关闭防火墙设置,可能通过systemctl stop firewalld这条指令来关闭该功能。
systemctl stop firewalld
刷新
firewall-cmd --reload
2.root用户远程访问
1.编辑/etc/my.cnf(编辑命令:vim /etc/my.cnf)文件里面在[mysqld]下面加上这句话
vim /etc/my.cnf
default_authentication_plugin=mysql_native_password
然后重启MySQL服务
systemctl start mysqld.service
2.登陆到mysql命令行:然后输入密码
mysql -u root -p
3.进入之后选择mysql库,用户信息都存在这个库的user表中
use mysql;
select host, user, authentication_string, plugin from user;
4.授权root用户可以远程登陆
update user set host='%' where user = 'root';
flush privileges;
5.设置服务自启动
开启
方式一
systemctl start mysqld.service
#
方式二
sudo systemctl enable --now mysqld
关闭
systemctl disable mysqld.service

浙公网安备 33010602011771号