Linux安装MySQL5.6的两种简单方法
【摘要】 Mysql的两种简单安装方式
=================================
/*
* @平台:华为云
* @描述:MySQL5.6安装的几种方法一
*/
=================================
一、安装基础软件
# yum install -y vim lrzsz wget httpd-tools net-tools gcc-c++ lsof openldap-devel nmap nc git bc iftop dos2unix iotop python-pip automake autoconf readline-devel sshpass
二、防火墙操作(安全组根据需求开放端口即可)
# systemctl enable --now firewalld
# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
# firewall-cmd --reload
success
三、安装方法一
-
下载官方rpm包并解压
# mkdir -p /home/data/mysql
# mkdir -p /home/softs/mysql
# cd /home/softs/
# wget https://cdn.mysql.com//Downloads/MySQL-5.6/MySQL-5.6.49-1.el7.x86_64.rpm-bundle.tar
# tar -xf MySQL-5.6.49-1.el7.x86_64.rpm-bundle.tar -C ./mysql/
-
安装
# cd mysql/
# yum localinstall -y ./* #安装本地rpm包,并解决依赖问题
-
初始化数据库
#查看默认初始密码
# cat ~/.mysql_secret
# The random password set for the root user at Tue Jan 25 21:52:49 2022 (local time): MxcHmlEtbimd0ax2
-
修改配置文件
# cp /etc/my.cnf /etc/my.cnf.old
# vim /etc/my.cnf
====content====
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
====end====
# systemctl start mysql
# netstat -antup |grep mysql
tcp6 0 0 :::3306 :::* LISTEN 8567/mysqld
-
修改密码(注意这样会留下历史记录,可以使用初始密码登录数据库修改)
# mysqladmin -uroot -pMxcHmlEtbimd0ax2 password root1234
四、安装方法二
-
创建mysql.repo源
# vim /etc/yum.repos.d/mysql.repo
====content====
# Enable to use MySQL 5.6
[mysql]
name=mysql
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
====end====
# yum clean all
# yum makecache
-
安装
# yum install -y mysql mysql-server mysql-devel mysql-test mysql-embedded mysql-shared-compat mysql-shared mysql-common
-
修改配置文件
# mkdir -p /home/data/mysql
# chown -R mysql:mysql /home/data/mysql/
# vim /etc/my.cnf
====content====
# datadir=/var/lib/mysql
datadir=/home/data/mysql
====end====
-
启动
# systemctl start mysql
# netstat -antup |grep mysql
tcp6 0 0 :::3306 :::* LISTEN 8567/mysqld
-
初始化
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the currentpassword for the root user.
If you've just installed MySQL, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.
Reload privilege tables now? [Y/n] y
... Success! All done! If you've completed all of the above steps, your MySQLinstallation should now be secure.
Thanks for using MySQL!
Cleaning up...
未完待续......
--本篇完--
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)