centos7中mysql(mariadb)数据库的安装使用

 1 # yum安装mariadb
 2 yum install mariadb mariadb-server
 3 # 如果需要安装自定义版本的mariadb,可以配置官方的仓库
 4 # 创建编辑mariadb.repo仓库文件
 5 vim /etc/yum.repos.d/MariaDB.repo
 6 # 添加下面参数。
 7     [mariadb]
 8     name = MariaDB
 9     baseurl = http://yum.mariadb.org/10.1/centos7-amd64        # 版本可自己更改
10     gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
11     gpgcheck=1
12 
13 # 然后在通过yum安装即可。
14 yum install MariaDB-server MariaDB-client -y
15 
16 # centos7中设置开启,关闭,重启,开机自启。
17 systemctl start mariadb
18 systemctl stop mariadb
19 systemctl restart mariadb
20 systemctl enable mariadb
21 
22 
23 # 正常数据库安装之后,最好要执行初始化命令,进行一些初始化设置,
24 # 否则默认的匿名用户,以及test数据库,会让数据库存在些安全隐患。。
25 mysql_secure_installation
26 
27 # 系统提示
28 Set root password? [Y/n] y            # 是否为root用户设置密码
29 Remove anonymous users? [Y/n] y        # 是否移除匿名用户
30 Disallow root login remotely? [Y/n] n        # 是否禁止root用户远程登录
31 Remove test database and access to it? [Y/n] y    # 是否删除test测试数据库
32 Reload privilege tables now? [Y/n] y        # 是否重新加载数据库授权表
33 
34 # 最后,Thanks for using MariaDB!初始化设置就完成了
35 
36 # 然后可以使用数据库了

 mariadb使用跟mysql的使用一样。。

 1 # 对用户的数据库授权操作
 2 
 3     grant 权限 on 数据库.表名 to 账户@主机名           # 对特定数据库中的特定表授权
 4     grant 权限 on 数据库.* to 账户@主机名              # 对特定数据库中的所有表给与授权
 5     grant 权限1,权限2,权限3 on *.* to 账户@主机名     # 对所有库中的所有表给与多个授权
 6     grant all privileges on *.* to 账户@主机名      # 对所有库和所有表授权所有权限
 7     revoke all privileges on *.* from 账户@主机名;        # 移除账户所有授权
 8     
 9 
10 # 如果要给数据库设置中文支持,可以打开数据库配置文件
11 vim /etc/my.cnf
12 
13     [mysqld]
14     character-set-server=utf8
15     collation-server=utf8_general_ci
16     log-error=/var/log/mysqld.log
17     datadir=/var/lib/mysql
18     socket=/var/lib/mysql/mysql.sock
19     # Disabling symbolic-links is recommended to prevent assorted security risks
20     symbolic-links=0
21     # Settings user and group are ignored when systemd is used.
22     # If you need to run mysqld under a different user or group,
23     # customize your systemd unit file for mariadb according to the
24     # instructions in http://fedoraproject.org/wiki/Systemd
25 
26     [mysqld_safe]
27     log-error=/var/log/mariadb/mariadb.log
28     pid-file=/var/run/mariadb/mariadb.pid
29 
30     [client]
31     default-character-set=utf8
32     [mysql]
33     default-character-set=utf8
34 
35     # include all files from the config directory
36     #
37     !includedir /etc/my.cnf.d
38 
39 # 以上加粗部分为添加的配置。

猜你喜欢

转载自www.cnblogs.com/NoteBook3013/p/10839818.html
今日推荐