浅记CentOS7安装MySQL
编辑
935
2022-09-03
1.如果已经安装MySQL或MariaDB,先卸载一下
yum search mysql
yum remove mariadb.x86_64
2.下载rpm包加载一下
官网 https://dev.mysql.com/downloads/repo/yum/
下载对应操作系统的安装包,我虚拟机是CentOS7我就拿这个了,可以换版本
上传到服务器,然后加载一下
yum localinstall mysql80-community-release-el7-7.noarch.rpm
找一下软件包的名称
yum search mysql
mysql-community-server.x86_64 : A very fast and reliable SQL database server
3.直接yum安装
yum -y install mysql-community-server.x86_64
4.启动,状态,自启
systemctl start mysqld
systemctl status mysqld
systemctl enable mysqld
5.登录,改密码,刷权限
先找root默认密码
grep 'password' /var/log/mysqld.log
2022-09-03T04:09:27.258187Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: HDpk:pkAJ5)A
登录
mysql -uroot -p
Enter password: HDpk:pkAJ5)A
第一步必须改密码,它不给其他操作,整复杂一点,刷完要退出重新登录一下
mysql> ALTER USER USER() IDENTIFIED BY 'XXxxxxx1234567,,.';
刷远程登录权限,正常root是不给远程登录的,我这只是个虚拟机简单省事就拉倒了
mysql> use mysql;
mysql> select user, host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
mysql> update user set host='%' where user='root';
mysql> flush privileges;
mysql> select user, host from user where user = 'root';
+------+------+
| user | host |
+------+------+
| root | % |
+------+------+
6.别忘了防火墙放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld
7.连接测试
8.如果连接报
public key retrieval is not allowed
就改一下连接属性
allowPublicKeyRetrieval=true
useSSL=false
配置什么的
配置文件
cat /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
bin-log
mysql> show variables like '%log_bin%';
+---------------------------------+-----------------------------+
| Variable_name | Value |
+---------------------------------+-----------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/binlog |
| log_bin_index | /var/lib/mysql/binlog.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+-----------------------------+
- 0
- 0
-
分享