练习linux下mysql的安装并测试成功
(1)检查Linux是否安装了mysql,在linux中执行以下命令:
rpm -qa | grep mysql
rpm -qa | grep mariadb
若是看到:"mariadb-libs-5.5.56-2.el7.x86_64",直接将其卸载,并卸载MySQL的依赖包文件,执行以下命令:
yum remove mariadb-libs-5.5.56-2.el7.x86_64
卸载mysql的依赖包:
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
(2)安装mysql所需要的工具包
yum install perl net-tools -y
(3)从Windows上上传以下文件,并依次安装
公告库类包:
mysql-community-common-5.7.20-1.el7.x86_64.rpm
libs依赖包:
mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql客户端包:
mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql服务器端依赖包:
mysql-community-server-5.7.20-1.el7.x86_64.rpm
上传方法(以下是通过Xftp上传):
打开Windows下的cmd命令:
sftp [email protected] #Linux主机的IP地址,执行后输入密码即可登录
然后切换到需要上传文件所在的文件夹,通过put命令上传文件
put (文件名称)
安装方法:
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
(4)初始化mysql数据库
mysqld --initialize
(5)查看mysql数据库的登录密码:
cat /var/log/mysqld.log
(6)更新mysql数据库目录的属主属组
chown mysql:mysql /var/lib/mysql -R
(7)启动mysql数据库
systemctl start mysqld #启动mysql数据库
systemctl status mysqld #查看启动状态
(8)登录mysql数据库:
进入mysql的安装目录:
cd /var/lib/mysql
执行命令:
mysql -uroot -p #执行后输入第五步得到的密码
若看到mysql命令行,即登录成功
(9) 修改mysql的登录密码,并使mysql允许远程登录:
set password=password('密码');
update user set host='%' where user='root';
flush privileges; #刷新权限
exit #退出mysql
(10)开启3306防火墙端口:
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
文章评论