MySQL/mariadb/centos安装:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 安装 == 搜索 MariaDB 现有的包 <syntaxhighlight lang="bash"> rpm -qa | grep mariadb</syntaxhighlight> 删除 MariaDB 现有的包 <syntaxhighlight lang="ba…”
 
Kangkk​(留言 | 贡献)
 
(未显示同一用户的3个中间版本)
第45行: 第45行:
mysql_secure_installation</syntaxhighlight>
mysql_secure_installation</syntaxhighlight>
=== 配置 MariaDB 的字符集 ===
=== 配置 MariaDB 的字符集 ===
查看/etc/my.cnf文件内容,其中包含一句!includedir /etc/my.cnf.d 说明在该配置文件中引入/etc/my.cnf.d 目录下的配置文件。
/etc/my.cnf


  1)使用vi server.cnf命令编辑server.cnf文件,在[mysqld]标签下添加
{{hc|my.cnf|<syntaxhighlight lang="mysql">
[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</syntaxhighlight>}}


init_connect='SET collation_connection = utf8_unicode_ci'
/etc/my.cnf.d/client.cnf
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]标签下添加以上内容。
{{hc|client.cnf|<syntaxhighlight lang="mysql">
[client]
default-character-set=utf8</syntaxhighlight>}}


2)文件/etc/my.cnf.d/client.cnf
/etc/my.cnf.d/mysql-clients.cnf


vi /etc/my.cnf.d/client.cnf
{{hc|mysql-clients.cnf|<syntaxhighlight lang="mysql">
在[client]中添加
[mysql]
default-character-set=utf8</syntaxhighlight>}}


default-character-set=utf8
{| class="wikitable"
3)文件/etc/my.cnf.d/mysql-clients.cnf
|-
 
|  || {{shc|<syntaxhighlight lang="bash">
vi /etc/my.cnf.d/mysql-clients.cnf
systemctl restart mariadb</syntaxhighlight>}}
在[mysql]中添加
|-
 
| MariaDB 查看字符集 || {{shc|<syntaxhighlight lang="mysql">
default-character-set=utf8
show variables like "%character%";show variables like "%collation%";</syntaxhighlight>|mysql>}}
全部配置完成,重启mariadb
|-
 
| 创建用户命令 || {{shc|<syntaxhighlight lang="mysql">
systemctl restart mariadb
create user username@localhost identified by 'password';</syntaxhighlight>|mysql>}}
之后进入MariaDB查看字符集
|-
 
| 直接创建用户并授权的命令 || {{shc|<syntaxhighlight lang="mysql">
mysql> show variables like "%character%";show variables like "%collation%";
grant all on *.* to username@localhost indentified by 'password';</syntaxhighlight>|mysql>}}
添加用户,设置权限
|-
 
| 授予外网登陆权限 || {{shc|<syntaxhighlight lang="mysql">
创建用户命令
grant all privileges on *.* to username@'%' identified by 'password';</syntaxhighlight>|mysql>}}
 
|-
mysql>create user username@localhost identified by 'password';
| 授予权限并且可以授权 || {{shc|<syntaxhighlight lang="mysql">
直接创建用户并授权的命令
grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;</syntaxhighlight>|mysql>}}
 
|}
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;