RHEL 6.7利用rpm完整包安裝MySQL-5.6.30

luashin發表於2016-05-11
利用rpm完整包安裝MySQL(MySQL-server-5.6.30 for rhel 6.7_64bit)
一、檢查作業系統上是否安裝了MySQL
[root@mydb1 backup]# rpm -qa |grep mysql
qt-mysql-4.6.2-26.el6_4.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
mysql-devel-5.1.71-1.el6.x86_64
mysql-libs-5.1.71-1.el6.x86_64

二、刪除MyQL(RedHat6.7伺服器自帶的mysql-libs是mysql-libs-5.1.61-4.el6.x86_64,可能會和高版本的mysql-libs有衝突)

[root@mydb1 backup]# rpm -qa |grep mysql*

[root@mydb1 backup]# yum -y remove mysql-libs-5.1.73-5.el6_6.x86_64


三、RPM安裝MySQL(用root使用者安裝,不需要提前建mysql組和mysql使用者,安裝mysql-server過程中會自動建立)

MySQL-6.30 Yum Repository

rhel6

rhel7



MySQL Yum源官方說明:

http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en

# Enable to use MySQL 5.7

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


# Enable to use MySQL 5.6

[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


下載rpm完整包安裝MySQL

[root@mydb1 backup]# wget

[root@mydb1 backup]# tar -xvf MySQL-5.6.30-1.el6.x86_64.rpm-bundle.tar

[root@mydb1 backup]# rpm -pql MySQL-server-5.6.23-1.el6.x86_64.rpm | more 
[root@mydb1 backup]# rpm -ivh MySQL-server-5.6.30-1.el6.i686.rpm
[root@mydb1 backup]# rpm -ivh MySQL-client-5.6.30-1.el6.x86_64.rpm
or
[root@mydb1 backup]# yum -y install MySQL-server* MySQL-client*


四、建立安裝目錄
[root@mydb1 backup]# mkdir -p /u01/app/mysql/data/mysql3306/{data,log,iblog,binlog,tmp}

五、配置my.cnf
[root@wmserpmysql1 ~]# cp -v /usr/my.cnf /u01/app/mysql/data/mysql3306/my.cnf
[root@wmserpmysql1 ~]# vim /u01/app/mysql/data/mysql3306/my.cnf
[client]
port=3306
socket=/u01/app/mysql/data/mysql3306/run/mysql.sock

[mysql]
port=3306
promprt=\\u@\\d \\r:\\m:\\s>

[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
explicit_defaults_for_timestamp=true
#dir
basedir=/usr
datadir=/u01/app/mysql/data/mysql3306/data
tmpdir=/u01/app/mysql/data/mysql3306/tmp

innodb_log_group_home_dir=/u01/app/mysql/log/mysql3306/iblog
innodb_data_home_dir=/u01/app/mysql/log/mysql3306/iblog
slave_load_tmpdir=/u01/app/mysql/data/mysql3306/tmp
log-error=/u01/app/mysql/data/mysql3306/log/alert.log
slow_query_log_file=/u01/app/mysql/data/mysql3306/log/slow.log
relay_log_info_file=/u01/app/mysql/log/mysql3306/binlog/relay-log.info
master-info-file=/u01/app/mysql/log/mysql3306/binlog/master.info
socket=/u01/app/mysql/data/mysql3306/run/mysql.sock
log-bin=/u01/app/mysql/log/mysql3306/binlog/binlog
relay-log=/u01/app/mysql/log/mysql3306/binlog/relaylog
innodb_force_recovery=0

六、執行MySQL安裝指令碼
[root@wmserpmysql1 ~]# sh init3306.sh
rm -rf /u01/app/mysql/mysql3306/data/*
rm -rf /u01/app/mysql/log/mysql3306/iblog/*
rm -rf /u01/app/mysql/log/mysql3306/binlog/*
chmod -R 777 /u01/app/mysql/data/mysql/3306/data/*
chmod -R 777 /u01/app/mysql/log/mysql3306/iblog/*
chmod -R 777 /u01/app/mysql/log/mysql3306/binlog/*
chmod 755 /u01/app/mysql/data/mysql3306/my.cnf
mysql_install_db --defaults-file=/u01/app/mysql/data/mysql3306/my.cnf --basedir=/usr/ --datadir=/u01/app/mysql/data/mysql3306/data

七、查是否有MySQL服務,如沒有新增mysql到服務開機啟動
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
檢視開機啟動設定是否成功
[root@mydb1 ~]# chkconfig --list | grep mysql
mysql          0:off  1:off  2:on    3:on    4:on    5:on    6:off

八、啟動MySQL
[root@mydb1 ~]# service mysql start
Starting MySQL SUCCESS! 
 
九、檢視MySQL執行狀態的方法
[root@mydb1 ~]# service mysql status
SUCCESS! MySQL running (4104)
 
十、查MySQL初始密碼
[root@mydb1 ~]# cat /root/.mysql_secret 
# The random password set for the root user at Mon Mar 30 15:04:58 2015 (local time): B15xIBTq3xAoGRVx

十一、登入MySQL
[root@mydb1 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.23
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

十二、修改密碼
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('guoyJoe123');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

使用root使用者進行遠端訪問
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql' WITH GRANT OPTION;

十三、my.cnf參考:
MySQL系統引數配置
先不啟動MySQL,複製資料目錄到新的位置/mysqldata,並修改許可權
[root@wmserpmysql1 /]# cd /var/lib/mysql/
[root@wmserpmysql1 /]# cp -r * /mysqldata/
[root@wmserpmysql1 /]# chown mysql:mysql -R /mysqldata

刪除原來預設的引數檔案
[root@wmserpmysql1 mysql]# rm /usr/my.cnf
rm: remove regular file `/usr/my.cnf'? y 

重新複製新的引數檔案,然後修改
[root@wmserpmysql1 mysql]# pwd
/usr/share/mysql
[root@wmserpmysql1 mysql]# cp my-default.cnf /etc/my.cnf
[root@wmserpmysql1 mysql]# vim /etc/my.cnf
修改引數檔案/etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock

[mysql]
no-auto-rehash 

[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir=/mysqldata
skip-name-resolve
character-set-server=utf8
lower_case_table_names=1
expire-logs-days=60
back_log = 500
max_connections = 5000
max_connect_errors =100000
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
thread_concurrency =16
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
thread_stack = 192K
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed 
slow_query_log_file=/mysqldata/localhost-slow.log
slow_query_log
long_query_time=1
relay-log=/mysqldata/relay-bin
server-id = 1
key_buffer_size = 32M
myisam_repair_threads = 1
myisam_recover
transaction_isolation = REPEATABLE-READ
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 10G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_per_table=1
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 6
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_flush_method=O_DIRECT
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 65535
log-error=/mysqldata/wmserpmysql1.800best.com.err
pid-file=/mysqldata/wmserpmysql1.800best.com.pid

十四、檢視及設定連線狀態
MySQL的最大連線數預設是100
客戶端登入:
mysql -uusername -ppassword

設定新的最大連線數為200:
mysql> set GLOBAL max_connections=200
顯示當前執行的Query:
mysql> show processlist

顯示當前狀態:
mysql> show status;
退出客戶端:
mysql> exit

檢視當前最大連線數:
mysqladmin -uusername -ppassword variables |find "max_con"
如:
C:\mysql\bin>mysqladmin -uroot -p variables | find "max_con"
Enter password:
| max_connections | 100
| max_connect_errors | 100

十五、查詢MySQL資料表的儲存引擎型別
提問: 想要知道MySQL資料庫是MyISAM還是Innodb型別。該如何檢查MySQL資料庫表的型別?
   MySQl使用的儲存引擎主要有兩種:MyISAM和Innodb。MyISAM是非事務的,因此擁有讀取更快,然而InnoDB完全支援細顆粒度的事務鎖定(比如:commit/rollback)。當建立一張新的MySQL表時,選擇它的型別(也就是儲存引擎)。如果沒有選擇,就會使用與預設定的預設引擎。如果想要知道已經存在的MySQL資料表的型別,以下幾種方法可以達到。
方法一
  訪問phpMyAdmin,從phpMyAdmin找出預設的資料庫型別。從phpMyAdmin中選中資料庫來檢視它的表列表。在“Type”一列的下面,將會看到每個表的資料表型別。
方法二
   可以直接登入MySQL伺服器,另外一種鑑別儲存引擎的方法是登入MySQL伺服器後執行下面的MySQL命令:
mysql> SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA ='my_database' AND TABLE_NAME ='my_table';
上面的命令會顯示在'mydatabase'資料庫中'mytable'表的引擎型別。
方法三
   還有一種檢查引擎的方法是使用mysqlshow,是一種命令列下的顯示資料庫資訊的工具。mysqlshow在MySQL 客戶端安裝包中有。要使用mysqlshow,需要提供MySQL伺服器登入憑據。
下面的命令會顯示特定的資料庫資訊。在“Engine”一列下面,可以看到每個表使用的引擎。
$ mysqlshow -u -p -i

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9034054/viewspace-2097596/,如需轉載,請註明出處,否則將追究法律責任。

相關文章