MariaDB安装与卸载 一、安装MariaDB 1. 安装MariaDB
安装命令
1 yum -y install mariadb mariadb-server
启动
设置开机启动
1 systemctl enable mariadb
对MariaDB进行相关简单配置
1 mysql_secure_installation
1 2 3 4 5 6 7 8 9 10 11 # 首先是设置密码,会提示先输入密码: Enter current password for root (enter for none):<–初次运行直接回车 # 设置密码: Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车 New password: <– 设置root用户的密码 Re-enter new password: <– 再输入一次你设置的密码 # 其他配置 Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车 Disallow root login remotely? [Y/n] <–是否禁止root远程登录,n, Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车 Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
初始化MariaDB完成,接下来测试登录
2. 关闭防火墙
关闭防火墙服务
1 2 systemctl status firewalld systemctl is-enabled firewalld
设置开机禁用防火墙服务
1 systemctl disable firewalld
临时关闭selinux
永久关闭selinux(建议永久关闭,需要重启才能生效)
1 2 vim /etc/selinux/config 修改成:SELINUX=disabled
3. 配置MariaDB的字符集 1 2 3 4 5 6 7 8 # 文件/etc/my.cnf vim /etc/my.cnf # 在[mysqld]标签下添加 init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake
1 2 3 4 # 文件/etc/my.cnf.d/client.cnf vim /etc/my.cnf.d/client.cnf # 在[client]中添加 default-character-set=utf8
1 2 3 4 # 文件/etc/my.cnf.d/mysql-clients.cnf vim /etc/my.cnf.d/mysql-clients.cnf # 在[mysql]中添加 default-character-set=utf8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 # 全部配置完成,重启mariadb systemctl restart mariadb # 之后进入MariaDB mysql -uroot -ppassword # 查看字符集 show variables like "%character%";show variables like "%collation%"; # 显示为 +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_unicode_ci | | collation_database | utf8_unicode_ci | | collation_server | utf8_unicode_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec) # 字符集配置完成。
4. 设置权限 授予外网登陆权限:
1 2 grant all privileges on *.* to root@'%' identified by 'password'; FLUSH PRIVILEGES;
参考命令:
1 2 3 4 5 6 # 创建用户命令 create user username@localhost identified by 'password'; # 直接创建用户并授权的命令 grant all privileges on *.* to username@localhost indentified by 'password'; # 授予权限并且可以授权 grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;
这时候用本地可视化工具连接虚机的mysql,应该就能成功了,如果还不行,就重启mariadb服务:
systemctl restart mariadb
或者重启虚机:reboot
命令~
5. 参考资料
参考博客:http://www.linuxidc.com/Linux/2016-03/128880.htm
二、卸载MariaDB 1. 停止MariaDB服务
2. 列出所有被安装的rpm package
3. 删除包: 1 2 3 rpm -e --nodeps mariadb-5.5.52-1.el7.x86_64 rpm -e --nodeps mariadb-server-5.5.52-1.el7.x86_64 rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
4. 删除之前卸载残留及配置文件 1 find / -name "mariadb" -exec rm -rf {} \;
再见 好了各位,以上就是这篇文章的全部内容了,能看到这里的人呀,都是人才 。
白嫖不好,创作不易。 各位的支持和认可,就是我创作的最大动力,我们下篇文章见!
如果本篇博客有任何错误,请批评指教,不胜感激 !