centos7 Mariadb 安装
时间:2019-02-10 22:11 来源:未知 作者:IT
1、安装MariaDB
安装命令
[root@node1 ~]# yum -y install mariadb mariadb-server
安装完成MariaDB,首先启动MariaDB
[root@node1 ~]# systemctl start mariadb
设置开机启动
[root@node1 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
接下来进行MariaDB的相关简单配置
[root@node1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
此处初次运行直接回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y 是否设置root用户密码,输入y并回车或直接回车
New password: 设置root用户的密码
Re-enter new password: 再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] 是否删除匿名用户,回车
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] 是否禁止root远程登录,回车,
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] 是否删除test数据库,回车
Dropping test database...
... Success!
Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] 是否重新加载权限表,回车
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB! (初始化MariaDB完成,接下来测试登录)!
[root@node1 ~]# mysql -uroot -ppassword
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 完成!!
下面我们正式进入 mariadb 的使用中!!
[root@node1 ~]# mysql -u root -p (-u:用户名,默认为root,-p:用户密码)
Enter password: (此处输入设置的密码)
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.60-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)]>
2、配置MariaDB的字符集
文件/etc/my.cnf
[root@node1 ~]# vim /etc/my.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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
Settings user and group are ignored when systemd is used.
If you need to run mysqld under a different user or group,
customize your systemd unit file for mariadb according to the
instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
include all files from the config directory
#
!includedir /etc/my.cnf.d
在[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/client.cnf
[root@node1 ~]# vim /etc/my.cnf.d/client.cnf
These two groups are read by the client library
Use it for options that affect all clients, but not the server
[client]
default-character-set=utf8
This group is not read by mysql client library,
If you use the same .cnf file for MySQL and MariaDB,
use it for MariaDB-only client options
[client-mariadb]
在[client]中添加: default-character-set=utf8
文件/etc/my.cnf.d/mysql-clients.cnf
[root@node1 ~]# vim /etc/my.cnf.d/mysql-clients.cnf
These groups are read by MariaDB command-line tools
Use it for options that affect only one utility
[mysql]
default-character-set=utf8
[mysql_upgrade]
[mysqladmin]
[mysqlbinlog]
[mysqlcheck]
[mysqldump]
[mysqlimport]
[mysqlshow]
[mysqlslap]
在[mysql]中添加: default-character-set=utf8
全部配置完成,重启mariadb systemctl restart mariadb
3、之后进入MariaDB查看字符集
[root@node1 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
MariaDB [(none)]>
至此,我们的实验完美结束! (责任编辑:IT)
1、安装MariaDB 安装命令 [root@node1 ~]# yum -y install mariadb mariadb-server 安装完成MariaDB,首先启动MariaDB [root@node1 ~]# systemctl start mariadb 设置开机启动 [root@node1 ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. 接下来进行MariaDB的相关简单配置 [root@node1 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): 此处初次运行直接回车 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y 是否设置root用户密码,输入y并回车或直接回车 New password: 设置root用户的密码 Re-enter new password: 再输入一次你设置的密码 Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] 是否删除匿名用户,回车 ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] 是否禁止root远程登录,回车, ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] 是否删除test数据库,回车 Dropping test database... ... Success! Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] 是否重新加载权限表,回车 ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! (初始化MariaDB完成,接下来测试登录)! [root@node1 ~]# mysql -uroot -ppassword ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 完成!! 下面我们正式进入 mariadb 的使用中!! [root@node1 ~]# mysql -u root -p (-u:用户名,默认为root,-p:用户密码) Enter password: (此处输入设置的密码) Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 5.5.60-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)]> 2、配置MariaDB的字符集 文件/etc/my.cnf [root@node1 ~]# vim /etc/my.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 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 Settings user and group are ignored when systemd is used. If you need to run mysqld under a different user or group, customize your systemd unit file for mariadb according to the instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # include all files from the config directory # !includedir /etc/my.cnf.d 在[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/client.cnf [root@node1 ~]# vim /etc/my.cnf.d/client.cnf These two groups are read by the client library Use it for options that affect all clients, but not the server [client] default-character-set=utf8 This group is not read by mysql client library, If you use the same .cnf file for MySQL and MariaDB, use it for MariaDB-only client options [client-mariadb] 在[client]中添加: default-character-set=utf8 文件/etc/my.cnf.d/mysql-clients.cnf [root@node1 ~]# vim /etc/my.cnf.d/mysql-clients.cnf These groups are read by MariaDB command-line tools Use it for options that affect only one utility [mysql] default-character-set=utf8 [mysql_upgrade] [mysqladmin] [mysqlbinlog] [mysqlcheck] [mysqldump] [mysqlimport] [mysqlshow] [mysqlslap] 在[mysql]中添加: default-character-set=utf8 全部配置完成,重启mariadb systemctl restart mariadb 3、之后进入MariaDB查看字符集 [root@node1 ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.60-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)]> show variables like "%character%";show variables like "%collation%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_unicode_ci | | collation_database | utf8_unicode_ci | | collation_server | utf8_unicode_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> 至此,我们的实验完美结束! (责任编辑:IT) |