Table of contents
Remote connection MySQL settings
MySQL download
Download the installation package
mkdir /usr/local/mysql
cd /usr/local/mysql
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
MySQL installation
decompress
tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
Detect MySQL installation environment
查看centos7中是否有MariaDB,MariaDB与MySQL关系请自行查阅
rpm -qa | grep mariadb
如果有MariaDB,需要将上述查询到的mairadb全部卸载,否则MySQL安装会出现问题
rpm -e --nodeps 软件名
查看本机是否已经安装过MySQL
rpm -qa | grep -i mysql
卸载MySQL
将步骤3中查询到的mysql安装包全部卸载
rpm -e --nodeps 软件名
查找mysql文件,并将其删除
find / -name mysql
whereis mysql
将find命令和whereis命令查询到的mysql文件全部删除
rm -rf 查询到的mysql路径
删除mysql配置文件
rm /etc/my.cnf
确认是否全部删除mysql
rpm -qa | grep -i mysql
Install 4
packages in order
Why install in order? because of dependencies
rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm --force --nodeps
database initialization
mysqld --initialize --user=mysql #yum install -y libaio
grep password /var/log/mysqld.log
Start the
mysql
service and enter
mysql
systemctl start mysqld
mysql -u root -p
change Password
mysql -u root -p
:进入
mysql
Alter user user() identified by 'newpassword'
: Change password
Remote connection MySQL settings
Check if mysql is installed
rpm -qa | grep mysql
whereis mysql
Check if mysql is running
service mysqld status
ps -ef|grep mysqld
ps aux|grep mysqld
pidof mysqld
Set remote connection root permissions
#进入到 mysql 中设置 root 用户权限
use mysql;
select user,host from user;
update user set host='%' where user='root';
grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges;
Look at port 3306 , see firewall details
netstat -an |grep 3306
Check
the status of
the firewall
firewall-cmd --state
see firewall rules
firewall-cmd --list-all
or
firewall-cmd --query-port=3306/tcp
If 3306
is not found
, set the firewall
to open port
3306
run the firewalld
firewall command, and reboot
:
firewall-cmd --zone=public --add-port=3306/tcp
firewall-cmd --zone=public --add-port=80/tcp –permanent
If you always report an error, start mysql or ssh to log in to linux remotely , and try again
firewall-cmd --reload
Service firewalld restart 重启
systemctl restart firewalld 重启
systemctl disable firewalld 关闭开机启动
CentOS7 database installation script
mkdir /usr/local/mysql
cd /usr/local/mysql
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm --force --nodeps
yum install -y libaio
mysqld --initialize --user=mysql
grep password /var/log/mysqld.log
systemctl start mysqld
mysql -u root -p
Alter user user() identified by '123456';
use mysql;
select user,host from user;
update user set host='%' where user='root';
grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges;