Centos7.9 mysql5.7离线安装
将Mysql7.5.44下载到本地,利用sftp工具上传到Centos7.9服务器
Linux-x86-x64 通用Mysql5.7.44下载
安装mysql前要先将mariadb卸载掉 yum remove mariadb* -y
tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz //将mysql压缩包解压
mv mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql //将以解压mysql包移动到/usr/local并重命名为mysql
将MySQL添加到系统变量
vi /etc/profile
#/etc/profile
export PATH=$PATH:/usr/local/mysql/bin //添加mysql执行文件路径
#
source /etc/profile //刷新环境变量
创建mysql用户
useradd mysql -M //-M:不创建家目录
初始化MySQL
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
创建my.cnf配置文件
vi /etc/my.cnf
#/etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
server_id=10
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
#
创建MySQL systemctl守护文件
vi /etc/systemd/system/mysqld.service
#/etc/systemd/system/mysqld.service
[Unit]
Description=mysql.server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
#
启动mysql
systemctl start mysqld.service //开启mysql服务
systemctl enable mysqld.service //开启开机自启
firewalld 开放mysql服务
firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload //重启firewalld
初始化mysql配置
mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: //默认即可
Please set the password for root here.
New password: //添加密码
Re-enter new password: //再次输入密码
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y //删除匿名用户
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y //不允许远程根用户登录
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //删除测试数据库并访问它
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y //现在重新加载特权表
Success.
All done!