CentOS7 yum方式安装MariaDB 10.2.13-1
注:以下步骤都是以root身份运行。
一、建立mariadb.repo
1,编辑新文件,命令:vim /etc/yum.repos.d/mariadb.repo
2,输入如下内容,保存退出
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos74-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
二、安装
1,输入命令
yum install mariadb-server mariadb-client -y
2,等待~_~...
三、配置系统
1,打开防火墙端口(是的,你没看错,服务还叫mysql!)
[root@mariadb ~]# firewall-cmd --permanent --add-service mysql success [root@mariadb ~]# firewall-cmd --reload success [root@mariadb ~]#
2,设置自启动,启动mariadb
[root@mariadb Downloads]# systemctl enable mariadb
[root@mariadb Downloads]# systemctl start mariadb
3,查看状态(mariadb 或mysql都可以)
[root@mariadb ~]# systemctl status mariadb ● mariadb.service - MariaDB 10.2.13 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/mariadb.service.d └─migrated-from-my.cnf-settings.conf Active: active (running) since Fri 2018-03-23 15:07:52 CST; 3min 48s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Process: 16847 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 16802 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS) Process: 16796 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Main PID: 16816 (mysqld) Status: "Taking your SQL requests now..." CGroup: /system.slice/mariadb.service └─16816 /usr/sbin/mysqld
四、配置mariadb
1,设置安全配置
[root@mariadb Downloads]# 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 New password: Re-enter new password: Sorry, passwords do not match. New password: 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] Y ... 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] Y ... 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] n ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... 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!
2,测试登录
[root@mariadb Downloads]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 17 Server version: 10.2.13-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)]>
3,设置mysql默认字符编码
[root@mariadb ~]# 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] ~
[root@mariadb ~]# vim /etc/my.cnf.d/server.cnf # # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon [mysqld] init_connect='SET collation_connection = utf8_general_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_general_ci skip-character-set-client-handshake default-storage-engine = innodb innodb_file_per_table max_connections = 4096 #开启慢查询 #slow_query_log = ON #slow_query_log_file = /usr/local/mysql/data/slow.log #long_query_time = 1 # # # * Galera-related settings #
MariaDB [(none)]> show variables like 'char%'; +--------------------------+----------------------------+ | 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) MariaDB [(none)]> show variables like 'colla%'; +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec) MariaDB [(none)]>
4,创建远程用户
MariaDB [mysql]> grant all privileges on *.* to user1@'%' identified by 'user188' with grant option;
五、打完收工^_^