Redhat 6 & CentOS 6

檢查MySQL狀態

rpm -qa | grep sql    

mysql-devel-5.1.73-5.el6_6.x86_64
mysql-libs-5.1.73-5.el6_6.x86_64
mysql-5.1.73-5.el6_6.x86_64

yum remove mysql

Dependencies Resolved

=============================================================================================================================
 Package                           Arch                 Version                          Repository                                                                                                     Size
=============================================================================================================================Removing:
 mysql                             x86_64               5.1.73-5.el6_6                   @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               2.4 M
 mysql-devel                       x86_64               5.1.73-5.el6_6                   @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               388 k
 mysql-libs                        x86_64               5.1.73-5.el6_6                   @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               4.0 M
Removing for dependencies:
 cronie                            x86_64               1.4.4-15.el6                     @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               174 k
 cronie-anacron                    x86_64               1.4.4-15.el6                     @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7                43 k
 crontabs                          noarch               1.10-33.el6                      @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               2.4 k
 pax                               x86_64               3.4-10.1.el6                     @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               135 k
 postfix                           x86_64               2:2.6.6-6.el6_5                  @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               9.7 M
 redhat-lsb                        x86_64               4.0-7.el6                        @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               0.0
 redhat-lsb-compat                 x86_64               4.0-7.el6                        @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               0.0
 redhat-lsb-core                   x86_64               4.0-7.el6                        @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7                22 k
 redhat-lsb-graphics               x86_64               4.0-7.el6                        @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               0.0
 redhat-lsb-printing               x86_64               4.0-7.el6                        @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               0.0
 sysstat                           x86_64               9.0.4-27.el6                     @anaconda-RedHatEnterpriseLinux-201507020259.x86_64/6.7               825 k

Transaction Summary
=====================================================================================================================================================================
Remove       14 Package(s)

Installed size: 18 M
Is this ok [y/N]: y

放入MariaDB相關安裝RPM
galera-25.3.14-1.rhel6.el6.x86_64.rpm
MariaDB-10.0.24-centos6-x86_64-common.rpm  
MariaDB-Galera-10.0.24-centos6-x86_64-server.rpm
MariaDB-10.0.24-centos6-x86_64-client.rpm  
MariaDB-10.0.24-centos6-x86_64-compat.rpm

rpm -ivh *.rpm
等待MariaDB安裝完成.

warning: galera-25.3.14-1.rhel6.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 1bb943db: NOKEY
Preparing...                ########################################### [100%]
   1:MariaDB-compat         ########################################### [ 20%]
   2:MariaDB-common         ########################################### [ 40%]
   3:MariaDB-client         ########################################### [ 60%]
   4:galera                 ########################################### [ 80%]
   5:MariaDB-Galera-server  ########################################### [100%]

   
service mysql start
Starting MySQL.. SUCCESS!

mysql -> 預設root沒有密碼, 可直接用mysql登入後再開始設定其他使用者帳號與DB權限


Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.0.24-MariaDB-wsrep MariaDB Server, wsrep_25.13.raf7f02e

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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


MariaDB [(none)]> select VERSION();
+-----------------------+
| VERSION()             |
+-----------------------+
| 10.0.24-MariaDB-wsrep |
+-----------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>


與目前線上版本相同, MariaDB(MySQL)就安裝完成了

可以從root建立相似的DB.


[root@Localhost ~]# mysql

MariaDB [(none)]> create database xxx_xxx;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]>

建立使用者

CREATE USER 'twmvmsap'@'localhost' IDENTIFIED BY 'Geme*477';

設定使用者可使用DB的權限

GRANT ALL PRIVILEGES ON xxx_xxx.* TO 'twmvmsap'@'vmsdb01';

GRANT ALL PRIVILEGES ON xxx_xxx.* TO 'twmvmsap'@'localhost';

GRANT ALL PRIVILEGES ON xxx_xxx.* TO 'twmvmsap'@'%';

後面要代host name是根據DB可以設定讓這帳號從哪邊進來
所以帳號權限建議要加上IP、localhost、%

MariaDB [mysql]> select user,password,host from user;
+----------+-------------------------------------------+-----------+
| user     | password                                  | host      |
+----------+-------------------------------------------+-----------+
| root     | *7A7041891FA5C539EE7549843F463FC1325D3E31 | localhost |
| root     |                                           | dbweb     |
| root     | *7A7041891FA5C539EE7549843F463FC1325D3E31 | 127.0.0.1 |
| root     | *7A7041891FA5C539EE7549843F463FC1325D3E31 | ::1       |
|          |                                           | localhost |
|          |                                           | dbweb     |
| xxxxxx   | *DF9149D7239960024607F9CC0F9D5689A47AAA5C | %         |
| cluster  | *81AAFC8D704B4A6C36A57F37D67A3E7FDCCAA8D6 | %         |
| cluster  | *81AAFC8D704B4A6C36A57F37D67A3E7FDCCAA8D6 | localhost |
| xxxxxx   | *DF9149D7239960024607F9CC0F9D5689A47AAA5C | localhost |
| centreon | *05D002BCE8739984DDC2CFB9430D590A3345AE9C | localhost |
+----------+-------------------------------------------+-----------+

=======================DB Schema匯入與匯出=======================

舊環境DB將所有Tables的Schema匯出,方便快速建立DB環境


mysqldump --single-transaction -uxxxxxxx -pxxxxxxx -d xxx_xxx > xxx_xxx.sql
                                (ID)        (Password)    (DB名稱)  (要匯入的名檔)    
 
當備份schema有出現Lock Tables時,可加上--single-transaction,讓匯出工作不會出現lock tables訊息

匯入的時候要先將DB建立好
MariaDB [(none)]> create database xxx_xxx;


MariaDB [(none)]> use xxx_xxx;
Database changed

show tables;
MariaDB [xxx_xxx]> show tables;
Empty set (0.00 sec)


使用root權限把匯出的DB schema匯入.

mysql -uroot -hxxxxxxxx xxx_xxx < xxx_xxx.sql

沒有出現錯誤訊息代表資料匯入OK

MariaDB [xxx_xxx]> show tables;
+-------------------+
| Tables_in_xxx_xxx |
+-------------------+
| cos               |
| greeting          |
| message           |
| notification      |
| sms               |
| smstransaction    |
| tmp               |
| transactions      |
| user              |
| user_test1        |
| user_test2        |
| web_audit         |
| web_user          |
+-------------------+
13 rows in set (0.00 sec)

數值的部份可以在手動或其他方式匯入,讓Labs可以順利運作.

arrow
arrow

    Rex Hsu 發表在 痞客邦 留言(0) 人氣()