导语
MariaDB 数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用 GPL 授权许可。 MYSQL被甲骨文公司收购后,有闭源的风险,所以一般都采用MariaDB。MariaDB 完全兼容mysql,使用方法也一样。
安装
<code>[root@localhost ~]# yum install mariadb-server/<code>
配置MariaDB
1.开启服务
<code>[root@localhost ~]# systemctl start mariadb # 开启服务
[root@localhost ~]# systemctl enable mariadb # 设置为开机自启动服务/<code>
2.首次安装进行数据库配置
<code> [root@localhost ~]# mysql_secure_installation/<code>
3. 配置时的各选项
<code># 输入数据库超级管理员root的密码(注意不是系统root的密码)
# 第一次进入还没有设置密码则直接回车
Enter current password for root (enter for none):
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。或者重启服务也许/<code>
4 测试数据库是否正常
<code>[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \\g.
Your MariaDB connection id is 145377
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.
MariaDB [(none)]>/<code>
出现MariaDB [(none)]>表示登录正常。
5. 创建用户
<code>CREATE USER 'username'@'host' IDENTIFIED BY 'password'; /<code>
username – 你将创建的用户名说明:
host – 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如 果想让该用户可以从任意远程主机登陆,可以使用通配符%
password – 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登 陆服务器
<code>GRANT privileges ON databasename.tablename TO 'username'@'host';/<code>
privileges – 用户的操作权限,如SELECT , INSERT , UPDATE 等(详细列表见该文最后面).如果要授予所 的权限则使用ALL说明:
databasename – 数据库名
tablename-表名,如果要授予该用户对所有数据库和表的相应操作权限则可用* 表示, 如*.*
7. 刷新数据库
<code>flush privileges;/<code>
閱讀更多 編程入門 的文章