CentOS 安装使用 MariaDB

2019/01/15

CentOS安装使用MariaDB

一、安装

1)在/etc/yum.repos.d/目录创建MariaDB.repo文件,内容如下:

# MariaDB 5.5 CentOS repository list - created 2014-03-04 11:20 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

注意:根据系统版本配置

2)在Shell环境下执行命令

# yum install MariaDB-server MariaDB-client

二、修改配置

配置文件在/etc下,my.cnf、my.cnf.d/ ,分为:mysql-clients.cnf server.cnf 客户端和服务端配置

1)修改服务端配置 /etc/my.cnf.d/server.cnf,增加一下内容:

[server]
# 服务端使用的字符集
character-set-server=utf8
# 表名不区分大小写
#lower_case_table_names=1
# 允许最大连接数
max_connections=1000
open_files_limit=100000
# 允许最大包大小
max_allowed_packet = 512M

2)修改客户端配置 mysql-clients.cnf,增加一下内容

# 设置mysql客户端默认字符集
default-character-set=utf8

三、启动

1)启动服务

[root@host yum.repos.d]# service mysql start
Starting MariaDB.181225 02:51:12 mysqld_safe Logging to '/var/lib/mysql/host.localdomain.err'.
181225 02:51:12 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
 SUCCESS! 

2)设置密码

mysqladmin -u root password 'root'  

3)设置开机启动

 chkconfig mysql on

4)初始化

mysql_secure_installation

四、使用

1.创建用户

CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 
  • host 说明
    • localhost: 只能本地使用
    • %:任意地方登陆
  • password 说明
    • 密码可以为空则不需要密码登陆服务器

2.重置密码

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');

3.登陆时重置密码

SET PASSWORD = PASSWORD("newpassword"); 

4.删除用户

DROP USER 'username'@'host'; 

5.授权

GRANT privileges ON databasename.tablename TO 'username'@'host' IDENTIFIED BY 'password'; 

6.撤销权限

REVOKE privilege ON databasename.tablename FROM 'username'@'host'; 

7.刷新权限

8.创建数据库

CREATE DATABASE `databasename` CHARACTER SET utf8 COLLATE utf8_general_ci;

demo

CREATE USER 'username'@'%' IDENTIFIED BY 'newpassword';
GRANT all privileges ON databasename.* TO 'username'@'%' IDENTIFIED BY 'password'; 
flush privileges;

(转载本站文章请注明作者和出处 mylater

Show Disqus Comments

Post Directory