2014年7月31日 星期四

[研究] CentOS 7 主要的 MySQL 變成 MariaDB 了

[研究] CentOS 7 主要的 MySQL 變成 MariaDB 了

2014-07-31
2014-08-01 修訂

[root@localhost ~]# yum list | grep mysql
akonadi-mysql.x86_64                       1.9.2-4.el7                 base
apr-util-mysql.x86_64                      1.5.2-6.el7                 base
dovecot-mysql.x86_64                       1:2.2.10-4.el7_0.1          updates
freeradius-mysql.x86_64                    3.0.1-6.el7                 base
libdbi-dbd-mysql.x86_64                    0.8.3-16.el7                base
mysql-connector-java.noarch                1:5.1.25-3.el7              base
mysql-connector-odbc.x86_64                5.2.5-6.el7                 base
php-mysql.x86_64                           5.4.16-21.el7               base
php-mysqlnd.x86_64                         5.4.16-21.el7               base
qt-mysql.i686                              1:4.8.5-8.el7               base
qt-mysql.x86_64                            1:4.8.5-8.el7               base
redland-mysql.x86_64                       1.0.16-6.el7                base
rsyslog-mysql.x86_64                       7.4.7-6.el7                 base
[root@localhost ~]#


[root@localhost ~]# yum search mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: mirror01.idc.hinet.net
============================== N/S matched: mysql ==============================
MySQL-python.x86_64 : An interface to MySQL
akonadi-mysql.x86_64 : Akonadi MySQL backend support
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
dovecot-mysql.x86_64 : MySQL back end for dovecot
freeradius-mysql.x86_64 : MySQL support for freeradius
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
mysql-connector-java.noarch : Official JDBC driver for MySQL
mysql-connector-odbc.x86_64 : ODBC driver for MySQL
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
qt-mysql.i686 : MySQL driver for Qt's SQL classes
qt-mysql.x86_64 : MySQL driver for Qt's SQL classes
qt3-MySQL.i686 : MySQL drivers for Qt 3's SQL classes
qt3-MySQL.x86_64 : MySQL drivers for Qt 3's SQL classes
redland-mysql.x86_64 : MySQL storage support for Redland
rsyslog-mysql.x86_64 : MySQL support for rsyslog
mariadb.x86_64 : A community developed branch of MySQL
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients

  Name and summary matches only, use "search all" for everything.
[root@localhost ~]#

上面,找 MySQL,出現 mariadb

[root@localhost system]# yum list | grep mariadb
mariadb.x86_64                             1:5.5.37-1.el7_0            @updates
mariadb-libs.x86_64                        1:5.5.37-1.el7_0            @updates
mariadb-server.x86_64                      1:5.5.37-1.el7_0            @updates
mariadb-bench.x86_64                       1:5.5.37-1.el7_0            updates
mariadb-devel.i686                         1:5.5.37-1.el7_0            updates
mariadb-devel.x86_64                       1:5.5.37-1.el7_0            updates
mariadb-embedded.i686                      1:5.5.37-1.el7_0            updates
mariadb-embedded.x86_64                    1:5.5.37-1.el7_0            updates
mariadb-embedded-devel.i686                1:5.5.37-1.el7_0            updates
mariadb-embedded-devel.x86_64              1:5.5.37-1.el7_0            updates
mariadb-libs.i686                          1:5.5.37-1.el7_0            updates
mariadb-test.x86_64                        1:5.5.37-1.el7_0            updates
[root@localhost system]#


[root@localhost ~]# yum -y install mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: mirror01.idc.hinet.net
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.37-1.el7_0 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.37-1.el7_0 for package: 1:mariadb-5.5.37-1.el7_0.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.35-3.el7 will be updated
---> Package mariadb-libs.x86_64 1:5.5.37-1.el7_0 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch          Version                 Repository      Size
================================================================================
Installing:
 mariadb             x86_64        1:5.5.37-1.el7_0        updates        8.9 M
Updating for dependencies:
 mariadb-libs        x86_64        1:5.5.37-1.el7_0        updates        752 k

Transaction Summary
================================================================================
Install  1 Package
Upgrade             ( 1 Dependent package)

Total size: 9.7 M
Total download size: 8.9 M
Downloading packages:
mariadb-5.5.37-1.el7_0.x86_64.rpm                          | 8.9 MB   00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:mariadb-libs-5.5.37-1.el7_0.x86_64                         1/3
  Installing : 1:mariadb-5.5.37-1.el7_0.x86_64                              2/3
  Cleanup    : 1:mariadb-libs-5.5.35-3.el7.x86_64                           3/3
  Verifying  : 1:mariadb-5.5.37-1.el7_0.x86_64                              1/3
  Verifying  : 1:mariadb-libs-5.5.37-1.el7_0.x86_64                         2/3
  Verifying  : 1:mariadb-libs-5.5.35-3.el7.x86_64                           3/3

Installed:
  mariadb.x86_64 1:5.5.37-1.el7_0

Dependency Updated:
  mariadb-libs.x86_64 1:5.5.37-1.el7_0

Complete!
[root@localhost ~]#


[root@localhost ~]# yum -y install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: mirror01.idc.hinet.net
No package mysql-server available.
Error: Nothing to do
[root@localhost ~]#

[root@localhost ~]# service mysqld restart
Redirecting to /bin/systemctl restart  mysqld.service
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
[root@localhost ~]#

[root@localhost ~]# yum -y install mariadb-server

[root@localhost system]# ls -a /usr/lib/systemd/system/mariadb.*
/usr/lib/systemd/system/mariadb.service
[root@localhost system]#

[root@localhost system]# service mariadb service
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
[root@localhost system]#

enable 會在作業系統啟動時,自動啟動服務
[root@localhost system]# systemctl enable  mariadb

start, stop, restart 等參數操作服務,不會有訊息
[root@localhost system]# systemctl start  mariadb

用 status 檢查服務狀態
[root@localhost system]# systemctl status  mariadb
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled)
   Active: active (running) since Thu 2014-07-31 17:16:05 CST; 46s ago
  Process: 15054 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 14975 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 15053 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           â”œâ”€15053 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           â””─15211 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socke...

Jul 31 17:16:03 localhost.localdomain mariadb-prepare-db-dir[14975]: http://dev.mysql.com
Jul 31 17:16:03 localhost.localdomain mariadb-prepare-db-dir[14975]: Support MariaDB development by buying support/new features from
Jul 31 17:16:03 localhost.localdomain mariadb-prepare-db-dir[14975]: SkySQL Ab. You can contact us about this at sales@skysql.com.
Jul 31 17:16:03 localhost.localdomain mariadb-prepare-db-dir[14975]: Alternatively consider joining our community based development effort:
Jul 31 17:16:03 localhost.localdomain mariadb-prepare-db-dir[14975]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
Jul 31 17:16:03 localhost.localdomain mysqld_safe[15053]: 140731 17:16:03 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jul 31 17:16:03 localhost.localdomain mysqld_safe[15053]: 140731 17:16:03 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jul 31 17:16:05 localhost.localdomain systemd[1]: Started MariaDB database server.
Jul 31 17:16:39 localhost.localdomain systemd[1]: Started MariaDB database server.
Jul 31 17:16:43 localhost.localdomain systemd[1]: Started MariaDB database server.

[root@localhost system]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.37-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \q
Bye
[root@localhost system]#

[root@localhost system]# ps aux | grep mariadb
mysql    15451  0.0  5.0 847184 94404 ?        Sl   17:17   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root     15577  0.0  0.0 112640   980 pts/1    R+   17:24   0:00 grep --color=auto mariadb

[root@localhost system]# ps aux | grep mysql
mysql    15293  0.0  0.0 115344  1684 ?        Ss   17:17   0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql    15451  0.0  5.0 847184 94404 ?        Sl   17:17   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root     15579  0.0  0.0 112640   976 pts/1    R+   17:24   0:00 grep --color=auto mysql
[root@localhost system]#

設定 資料庫 root 的密碼

[root@localhost ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
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]
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]
 ... 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]
 ... 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]
 - 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!
[root@localhost ~]#

測試

[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.37-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@localhost ~]#


防火牆相關命令

# firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=8080/tcp

(完)

沒有留言:

張貼留言