Linux(CentOS7)yum安装卸载MySql数据库(V5.7)详细操作图解常见问题演⽰环境说明
安装MySql的时候会默认创建⼀个mysql组和⼀个mysql⽤户,并把datadir和安装⽬录属主改为mysql,在MySQL启动的时候,单进程mysqld,该进程的属主就是mysql,这样就保证了mysql服务的独⽴性,
即便mysql服务被⿊掉,得到了mysql⽤户权限,也不会影响整个系统的安全,mysql⽤户是不登陆的,所以默认没有密码,只是给MySQL服务 ⼀个运⾏的⽤户,默认安装在/usr/bin/mysql⽬录。
⼀、yum安装MySql
广告代码有哪些格式1.1、下载rpm包
# mkdir -p /opt/software
# cd /opt/software/
# wget -i -c sql/arch.rpm
# du -arch.rpm
arch.rpm
1.2、安装rpm包
# sudo yum -y arch.rpm
# ll /pos.d
总⽤量 12
-rw-r--r--. 1 root root 1627 4⽉ 5 po
-rw-r--r--. 1 root root 1663 4⽉ 5 po
linux修改口令的命令#
rpm安装后,/pos.d/⽬录会新增两个mysql的repo源:po,po。需要安装哪个版本将⽂件po中版本对应的enabled改成1,其他的改成0。
1.3、安装mysql
# sudo yum -y install mysql-community-server
安装有点慢,耐⼼等待完成即可。
⾄此MySql安装完成,它包含了四个包[common、libs、client、server],并创建了mysql⽤户和组。
# rpm -qa | grep -i mysql
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
# id mysql
uid=27(mysql) gid=27(mysql)组=27(mysql)
#
1.4、启动MySql查看状态设置开机⾃启动
# systemctl start mysqld
# systemctl enable mysqld
# systemctl status mysqld
1.5、查初始密码,并重置密码
# cat /var/log/mysqld.log | grep password
2022-01-28T03:14:27.055571Z 1 A temporary password is generated for root@localhost: Bu*wbhz)u2vs
#
这⾥的Bu*wbhz)u2vs就是root的初始密码。
1.6、登录MySql重置密码
使⽤查询到的临时密码使⽤命令mysql -u root -p登录MySQL,修改密码
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
jsp与javabean实验总结Type'help;' or '\h'for help.Type'\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'zhj@AaZz123456';
Query OK, 0 rows affected (0.00 sec)
mysql>
5.7增加了策略更改密码必须满⾜:数字、⼩写字母、⼤写字母 、特殊字符、长度⾄少8位,如果设设置太简单,会设置失败会提⽰密码不安全。如果想去掉可在/etc/myf配置⽂件中[mysqld]节点下增加validate_password=off配置,重启数据库通过SHOW PLUGINS;即可看到密码验证的插件被停⽌了。
1.7、授权远程远程登录(两种都设置)
1、改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登⼊mysql后,更改“mysql” 数据库⾥的 “root” 表⾥的 “host” 项,从"localhost"改称"%"
mysql> use mysql;
connected翻译Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host, user from user;
2、授权法。例如,你想root使⽤password从任何主机连接到mysql服务器的话。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'zhj@AaZz123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
cms采集插件mysql>
如果你想允许⽤户root从192.168.56.166的主机连接到mysql服务器
GRANT ALL PRIVILEGES ON . TO ‘root’@‘192.168.56.166’ IDENTIFIED BY ‘zhj@AaZz123456’ WITH GRANT OPTION;
1.8、通过远程⼯具验证:
如果需要修改MySql的⽬录,可以修改/etc/myf配置⽂件,改成对应的⽬录,重启即可。⼆、MySql数据库完全卸载
html自定义表单2.1、关闭MySql关闭开机⾃启动
# systemctl stop mysqld
# systemctl disable mysqld
2.2、查看rpm
# rpm -qa | grep -i mysql
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
2.3、卸载rpm
# rpm -e --nodeps mysql-community-libs-5.7.37-1.el7.x86_64
# rpm -e --nodeps mysql-community-server-5.7.37-1.el7.x86_64
# rpm -e --arch
警告:/pos.po 已另存为/pos.po.rpmsave # rpm -e --nodeps mysql-community-common-5.7.37-1.el7.x86_64
# rpm -e --nodeps mysql-community-client-5.7.37-1.el7.x86_64
#
2.3、查看yum安装mysql
# yum list install mysql*
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun
* extras: mirrors.aliyun
* updates: mirrors.aliyun
错误:没有匹配的软件包可以列出
#
2.4、卸载对应的包
# yum remove mysql-community-release
2.5、查看并删除对应的⽬录
# whereis mysql
mysql: /usr/lib64/mysql /usr/share/mysql
# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/
var/lib/mysql/mysql
/usr/lib64/mysql
/usr/share/mysql
/data/mysql
# rm -rf /usr/lib64/mysql
# rm -rf /usr/share/mysql
# rm -rf /etc/selinux/targeted/active/modules/100/mysql
# rm -rf /var/lib/mysql/mysql
# rm -rf /var/lib/mysql
# rm -rf /data/mysql
2.6、删除配置⽂件
# rm -rf /root/.mysql_sercret
# rm -rf /etc/myf.rpmsave
# rm -rf /var/log/mysqld.log
2.7、查看组和⽤户并删除
# cat /etc/group
# cat /etc/passwd
# groupdel mysql
# userdel mysql
⾄此MySql已完全卸载成功。
三、安装问题处理
3.1、在CentOS上使⽤yum安装MySQL时检索密钥错误的解决⽅法
编辑⽂件
/pos.po
修改对应安装版本的gpgcheck值默认1改成0,再次重新安装。
3.2、登录时报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)
原因是/var/lib/mysql的访问权限问题。下⾯的命令把/var/lib/mysql的拥有者改为当前⽤户:
# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
# sudo chown -R mysql:mysql /var/lib/mysql
#
# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
# mysql -u root
然后,重启服务,重新进⼊
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论