记录下官网里用yum rpm源安装mysql,
1· 官网下载rpm https://dev.mysql.com/downloads/repo/yum/
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html(附官网操作手册)
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm #注意区分你是centos7还是8,el后边代表你的系统版本
2·yum 安装mysql源
yum localinstall mysql80-community-release-el7-3.noarch.rpm |就是你刚才下载的rpm文件的名字
3·检查是否成功安装
yum repolist enabled | grep "mysql.*-community.*"
4·查看 和 选择你想开启的mysql版本,5.7或者8.0
yum repolist all | grep mysql #查看现在是开启的哪个版本的mysql源,如下图(图忘截了,就看每一行后边是enable还是disable)
yum-config-manager --disable mysql80-community #关闭8.0的源
yum-config-manager --enable mysql57-community #开启5.7的源
5·安装mysql
yum install mysql-community-server #安装
service mysqld start #启动
systemctl start mysqld #第二种启动方法
!!!!!到这里也许会提示 Redirecting to /bin/systemctl start mysqld.service
输入 systemctl restart mysqld.service 然后再
service mysqld status # 查看状态 mysqld (pid 3066) is running
systemctl enable mysqld #开机启动
systemctl daemon-reload
6·设置root用户
sudo grep 'temporary password' /var/log/mysqld.log #用错误日志来修改密码
mysql -uroot -p # 日志中的初始密码来登上mysql
SHOW VARIABLES LIKE 'validate_password%'; #mysql命令行里用这个是查看设置密码的规则,复杂程度,想修改的话百度一下修改密码复杂度
ALTER USER 'root'@'localhost' IDENTIFIED BY '这里填你的密码'; #大写小写数字加特殊
7·设置远程登录链接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_root_password' WITH GRANT OPTION;
FLUSH PRIVILEGES; #应用此设置
8·查看端口号,防火墙放行
show global variables like 'port'; # mysql 命令行下使用
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
firewall-cmd --list-ports #查看当前已经开放的端口:
firewall-cmd --zone=public --add-port=8888/tcp --permanent #开启端口,以8888为例:
firewall-cmd --reload #重启防火墙:
#####其他指令:
firewall systemctl stop firewalld.service # 关闭防火墙
firewall sustemctl disable firewalld.service # 关闭防火墙开机启动
firewalld的基本使用
附录:systemctl开关防火墙
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
9·移动数据库数据的存放地址:
df -h #查看磁盘使用情况,如下
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 13G 5.4G 7.7G 42% / #重要
devtmpfs 485M 0 485M 0% /dev
tmpfs 494M 4.0K 494M 1% /dev/shm
tmpfs 494M 6.6M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot #重要
tmpfs 99M 0 99M 0% /run/user/0
·········································································
du -h --max-depth=1 /var/lib/mysql/ #查看每个文件大小和最下边是总大小,这里更改存放路径就和Windows C盘 D盘一样
cp /etc/my.cnf /etc/my.cnfbak #备份配置文件一份!
systemctl stop mysqld #先停止服务
vim /etc/my.cnf #编辑配置文件
datadir = /local/soft/mysql #修改这个值,表示放到这个文件夹中,复制数据,不要mv,一万防以。cp /var/lib/myql /local/soft/mysql
socket = /local/soft/mysql/mysql.sock #修改这个值
添加下边这个值
[client] #这个也要打上!!!!
socket = /local/soft/mysql/mysql.sock #这个添加一遍
重启服务!!!!