最近想折腾一下我的vps练练技术,记录一下步骤,供以后参考。
本来想装Mysql来着,但是感觉安装麻烦点,而且官网版本有些眼花缭乱的,试试MySQL同父同源的MariaDB。
首先查询是否安装过,我因为刚开始打算安装MySQL,就把MariaDB给卸载了。。。
一、通过yum安装MariaDB
输入命令:yum install mariadb-server
安装mariadb-server,默认依赖安装mariadb,一个是服务端、一个是客户端。
然后输入 y 下载包,并进行安装
接下来就安装完成了:
二、开始配置MariaDB
开启MariaDB服务,设置开机启动
[root@localhost bin]# systemctl start mariadb # 开启服务
[root@localhost bin]# systemctl enable mariadb # 设置为开机自启动服务
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
首次安装进行数据库的配置
输入命令进行配置:mysql_secure_installation
这里要求输入数据库的root密码,刚安装的还没设置密码,直接按回车就好
Enter current password for root (enter for none): # 输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车
Set root password? [Y/n] # 设置密码,y
New password: # 新密码
Re-enter new password: # 再次输入密码
Remove anonymous users? [Y/n] # 移除匿名用户, y
Disallow root login remotely? [Y/n] # 拒绝root远程登录,n,不管y/n,都会拒绝root远程登录
Remove test database and access to it? [Y/n] # 删除test数据库,y:删除。n:不删除,数据库中会有一个test数据库,一般不需要
Reload privilege tables now? [Y/n] # 重新加载权限表,y。或者重启服务也行
测试一下是否能登录
mysql -uroot -p之后输入密码,登录成功了。
以下内容摘抄自:https://www.cnblogs.com/yhongji/p/9783065.html
设置MariaDB字符集为utf-8
1)/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
2)/etc/my.cnf.d/client.cnf 文件
在 [client] 标签下添加
default-character-set=utf8
3)/etc/my.cnf.d/mysql-clients.cnf 文件
在 [mysql] 标签下添加
default-character-set=utf8
4)重启服务
[root@mini ~]# systemctl restart mariadb
5)进入mariadb查看字符集
MariaDB [(none)]> show variables like "%character%";show variables like "%collation%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec) +----------------------+-------------------+ | Variable_name | Value | +----------------------+-------------------+ | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +----------------------+-------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> 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) MariaDB [(none)]>
远程链接mariadb数据库
mariadb默认是拒绝 root 远程登录的。这里用的是 navicat 软件连接数据库
1)关闭防火墙
① 关闭防火墙 systemctl stop firewalld
[root@mini ~]# systemctl stop firewalld
② 在不关闭防火墙的情况下,允许某端口的外来链接。步骤如下,开启3306端口,重启防火墙
[root@mini ~]# firewall-cmd --query-port=3306/tcp # 查看3306端口是否开启 no [root@mini ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开启3306端口 success [root@mini ~]# firewall-cmd --reload # 重启防火墙 success [root@mini ~]# firewall-cmd --query-port=3306/tcp # 查看3306端口是否开启 yes
[root@mini ~]# mysql -u root -p # 先通过本地链接进入数据库 MariaDB [(none)]> use mysql; MariaDB [mysql]> select host, user from user; +-----------+------+ | host | user | +-----------+------+ | 127.0.0.1 | root | | ::1 | root | | mini | root | +-----------+------+ 3 rows in set (0.00 sec)
MariaDB [mysql]> update user set host='%' where host='mini'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [mysql]> select host, user from user; +-----------+------+ | host | user | +-----------+------+ | % | root | | 127.0.0.1 | root | | localhost | root | +-----------+------+ 3 rows in set (0.00 sec)
4)刷新权限表,或重启mariadb服务,一下二选一即可
MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec)
[root@mini ~]# systemctl restart mariadb
注意:刷新权限表是在数据库中,重启服务是在外部命令行中
6)重新远程链接mariadb
本网站尊重知识产权,如有侵权,请及时联系我们删除。
本站所有原创内容仅用于学习和交流目的,未经作者和本站授权不得进行商业使用或盈利行为。
暂无评论内容