MySQL/mariadb/centos安装

来自康健生活
Kangkk​(留言 | 贡献)2020年2月23日 (日) 08:36的版本 (创建页面,内容为“== 安装 == 搜索 MariaDB 现有的包 <syntaxhighlight lang="bash"> rpm -qa | grep mariadb</syntaxhighlight> 删除 MariaDB 现有的包 <syntaxhighlight lang="ba…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

安装

搜索 MariaDB 现有的包

rpm -qa | grep mariadb

删除 MariaDB 现有的包

rpm -e --nodeps mariadb-*

或者

yum remove

创建MariaDB.repo

vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.2.4 CentOS repository list - created 2017-05-05 16:13 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum -y install mariadb MariaDB-server MariaDB-client
systemctl start mariadb
systemctl enable mariadb
标题文字 标题文字
systemctl start mariadb 启动服务
systemctl enable mariadb 设置开机启动
systemctl restart mariadb 重新启动
systemctl stop mariadb.service 停止MariaDB
示例 示例

进行MariaDB的相关简单配置

mysql_secure_installation

配置 MariaDB 的字符集

查看/etc/my.cnf文件内容,其中包含一句!includedir /etc/my.cnf.d 说明在该配置文件中引入/etc/my.cnf.d 目录下的配置文件。

  1)使用vi server.cnf命令编辑server.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


  如果/etc/my.cnf.d 目录下无server.cnf文件,则直接在/etc/my.cnf文件的[mysqld]标签下添加以上内容。

2)文件/etc/my.cnf.d/client.cnf

vi /etc/my.cnf.d/client.cnf 在[client]中添加

default-character-set=utf8 3)文件/etc/my.cnf.d/mysql-clients.cnf

vi /etc/my.cnf.d/mysql-clients.cnf 在[mysql]中添加

default-character-set=utf8

全部配置完成,重启mariadb

systemctl restart mariadb 之后进入MariaDB查看字符集

mysql> show variables like "%character%";show variables like "%collation%"; 添加用户,设置权限

创建用户命令

mysql>create user username@localhost identified by 'password'; 直接创建用户并授权的命令

mysql>grant all on *.* to username@localhost indentified by 'password'; 授予外网登陆权限

mysql>grant all privileges on *.* to username@'%' identified by 'password'; 授予权限并且可以授权

mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;