[MariaDB]Linux 快速安装MariaDB
在 Linux 操作系统下,快速安装 MariaDB
(一)删除老版本的MariaDB
在安装前要先确定系统是否已经安装了其他版本的MariaDB,如已安装其他版本的MariaDB,需先删除后再安装新版本。经本文亲测,采用如下方式删除老版本的MariaDB或MariaDB残留文件作为方便。
1.执行yum命令,删除MariaDB的lib库,服务文件
rpm -qa | grep -i mariadb;
yum -y remove mariadb-libs*;
yum autoremove mariadb mariadb-server -y;
2.执行find命令,查找MariaDB的残留文件,然后运行“rm -rf 文件名”删除残留的MariaDB文件
find / -name mariadb;
rm -rf #文件名;
(二)RPM格式安装MariaDB
1.快速安装。
yum -y install mariadb mariadb-server;
2.启动服务
systemctl start mariadb;
3.设置开机启动
systemctl enable mariadb;
4.设置相关配置
mysql_secure_installation;
- 首先是设置密码,会提示先输入密码
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远程登录,回车,
Remove test database and access to it? [Y/n] #是否删除test数据库,回车
Reload privilege tables now? [Y/n] #是否重新加载权限表,回车
5.登录
mysql -uroot -ppassword;
6.使用mysql数据库
use mysql;
7.设置远程访问授权
grant all on *.* to 'root'@'%'identified by 'password';
8.刷新权限缓存
flush privileges;
9.编码配置,支持移动端的表情
- 停止服务
systemctl stop mariadb;
- 停止服务
编辑/etc/my.cnf
在[mysqld]标签下添加下面内容
default-storage-engine = innodb
innodb_file_per_table
max_connections = 4096
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4编辑/etc/my.cnf.d/client.cnf
在[client]标签下添加下面内容
default-character-set=utf8mb4编辑/etc/my.cnf.d/mysql-clients.cnf
在[mysql]标签下添加下面内容
default-character-set=utf8mb4
10.CentOS7使用firewalld防火墙开放3306端口
- 打开防火墙配置文件
firewall-cmd --zone=public --add-port=80/tcp --permanent; #permanent永久生效,没有此参数重启后失效
- 重启防火墙
firewall-cmd --reload;
- 查看防火墙所有打开的端口
firewall-cmd --zone=public --list-ports;
如果遇到警告
- 密码连接错误
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
systemctl stop mariadb; #停止MariaDB
mysqld_safe -skip-grant-tables; #用以下命令启动MySQL,以不检查权限的方式启动
mysql -u root mysql; #然后用空密码方式使用root用户登录mysql
UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; #修改新密码
flush privileges; #刷新权限缓存
quit; #退出mysql
systemctl restart mariadb; #重启MariaDB