wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-release-el7-5.noarch.rpm yum install mysql-community-server
service mysqld restart
mysql -u root mysql> set password for 'root'@'localhost' =password('vm_52.102');
[root@localhost liuhui]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service [root@localhost liuhui]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.34 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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> set password for 'root'@'localhost' =password('password'); Query OK, 0 rows affected (0.00 sec)
正常進程html
[root@localhost liuhui]# ps aux|grep mysqld mysql 59735 0.0 0.0 113124 1580 ? Ss 16:18 0:00 /bin/sh /usr/bin/mysqld_safe mysql 59900 0.1 6.3 698924 118004 ? Sl 16:18 0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
===============================================python
【安裝過程當中的錯誤】mysql
一、軟件包依賴 mariadb組件linux
錯誤:軟件包:akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda) 須要:mariadb-server 正在刪除: 1:mariadb-server-5.5.44-2.el7.centos.x86_64 (@anaconda) mariadb-server = 1:5.5.44-2.el7.centos 取代,由: mysql-community-server-5.6.34-2.el7.x86_64 (mysql56-community) 未找到 更新,由: 1:mariadb-server-5.5.50-1.el7_2.x86_64 (updates) mariadb-server = 1:5.5.50-1.el7_2 可用: 1:mariadb-server-5.5.47-1.el7_2.x86_64 (updates) mariadb-server = 1:5.5.47-1.el7_2 您能夠嘗試添加 --skip-broken 選項來解決該問題 您能夠嘗試執行:rpm -Va --nofiles --nodigest
解決:移除對 mariadb-libs的依賴c++
yum -y remove mariadb-libs
二、在阿里雲機器上遇到 libc.so.6(GLIBC_2.17)依賴問題sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
Error: Package: mysql-community-client-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-libs-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: 2:postfix-2.6.6-6.el6_7.1.x86_64 (base)
Requires: libmysqlclient.so.16(libmysqlclient_16)(64bit)
Removing: mysql-libs-5.1.73-3.el6_5.x86_64 (@updates)
libmysqlclient.so.16(libmysqlclient_16)(64bit)
Obsoleted By: mysql-community-libs-5.6.35-2.el7.x86_64 (mysql56-community)
Not found
Updated By: mysql-libs-5.1.73-8.el6_8.x86_64 (updates)
libmysqlclient.so.16(libmysqlclient_16)(64bit)
Available: mysql-libs-5.1.73-7.el6.x86_64 (base)
libmysqlclient.so.16(libmysqlclient_16)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
Error: Package: 2:postfix-2.6.6-6.el6_7.1.x86_64 (base)
Requires: libmysqlclient.so.16()(64bit)
Removing: mysql-libs-5.1.73-3.el6_5.x86_64 (@updates)
libmysqlclient.so.16()(64bit)
Obsoleted By: mysql-community-libs-5.6.35-2.el7.x86_64 (mysql56-community)
Not found
Updated By: mysql-libs-5.1.73-8.el6_8.x86_64 (updates)
libmysqlclient.so.16()(64bit)
Available: mysql-libs-5.1.73-7.el6.x86_64 (base)
libmysqlclient.so.16()(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64 (mysql56-community)
Requires: systemd
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
|
【mysql的啓動和中止】shell
# 1) 啓動 ---官方推薦使用 mysqld_safe 進程啓動,遇到mysqld進程中止,mysqld_safe自動從新啓動 nohup /bin/sh /usr/bin/mysqld_safe & #2) 中止 使用 shutdown中止mysql mysqladmin -uroot -p shutdown;
===============================================數據庫
【mysql啓動錯誤】vim
檢查mysql的錯誤日誌發現 是配置文件問題centos
cat /var/log/mysqld.log |grep ERROR
2016-12-05 16:08:12 57836 [ERROR] /usr/sbin/mysqld: unknown variable 'default-character-set=utf8' 2016-12-05 16:08:12 57836 [ERROR] Aborting
vim /etc/my.cnf
#default-character-set=utf8 character_set_server=utf8
把字符集編碼的設置 更改一下,default 改成character_set
===============================================
【mysql運維演練】
一、修改mysql的默認數據庫路徑,轉移到指定目錄~/mysql_data下
【command list】
(1)停服務 copy文件 mysqladmin -uroot -p shutdown; cd /var/lib cp -a -r /var/lib/mysql /home/mysql_data/ chown mysql:mysql /home/mysql_data/mysql chmod 4777 /home/mysql_data/mysql/mysql.sock chmod a+x /home/mysql_data/ chmod mysql:mysql a+x /home/mysql_data/
# 啓動mysql /bin/sh /usr/bin/mysqld_safe (2)修改3個配置 cp /etc/my.cnf /etc/my.cnfbak cp /usr/bin/mysqld_safe /usr/bin/mysqld_safebak vim /etc/my.cnf datadir=/home/mysql_data/mysql socket=/home/mysql_data/mysql/mysql.sock
vim /usr/bin/mysqld_safe datadir=/home/mysql_data/mysql (3)創建連接 ln -s /home/mysql_data/mysql/mysql.sock /var/lib/mysql/mysql.sock
再啓動mysql
/bin/sh /usr/bin/mysqld_safe
二、部分配置參數的意義整理
interactive_timeout=300 #服務器關閉交互式鏈接前等待活動的秒數,單位秒,默認8小時,28800秒。避免閒置鏈接過多。 wait_timeout=300 #服務器關閉非交互鏈接以前等待活動的秒數與iteractive_timeout一塊兒設置客戶端超時時間。 #只有 wait_timeout 會真正起到超時限制的做用 interactive_timeout和wait_timeout在鏈接空閒階段(sleep)起做用 max_allowed_packet=16M #消息緩衝區包的最大大小 net_read_timeout=180 #在終止讀以前,從一個鏈接得到數據而等待的時間秒數; 當服務正在從客戶端讀取數據時,net_read_timeout控制什麼時候超時 net_write_timeout=180 # 在終止寫以前,等待多少秒把block寫到鏈接; 當服務正在寫數據到客戶端時,net_write_timeout控制什麼時候超時 net_read_timeout和net_write_timeout:則是在鏈接繁忙階段(query)起做用 max_connect_errors=10000 #主機在鏈接被中斷(網絡,或者程序意外中斷)等,都會增長 connect_errors的計數值,
當超過了閾值就只能被 blocked,若是鏈接成功,計數值又會被初始爲0;若是出現錯誤,仍是老老實實的 flush hosts吧 max_connections=1000 #mysql 最大鏈接數 connect_timeout=20 # 在獲取鏈接階段(authenticate)起做用 bulk_insert_buffer_size = 256M # 批量insert腳本大小設置,有 blob大字段要設置大一些,
二、查詢結果導出到文件
1) 直接命令行執行
mysql -h 127.0.0.1 -uroot -p -Ne "use test; select * from test limit 100;" > /tmp/outdata.txt
2) 命令行調用sql文件執行
vim run_out.sql
use test; select * from test limit 100;
mysql -uroot -p -N < run_out.sql > /tmp/outdata.txt
三、mysql 數據導入
#【source 和 load data infile 命令,進入mysql】
mysql > use test
mysql > set names utf8
mysql > source /home/mysql_data/test.sql; #load data ,注意 local參數。 如下生成測試數據 並導入測試表
python -c "for i in range(1,1+1000000): print(i)">100w.txt
mysql > create table tmp_series(id int,primary key(id));
mysql > load data local infile '/home/test/100w.txt' replace into table tmp_series; -------------------------------- [不加local參數,報錯] ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
四、Innodb 和 myisam 存儲引擎的差別
Innodb 須要事務處理或是外鍵,update更快些,嚴格保持數據一致性時更適合;
select count from tables, innodb實時去掃描表計數,慢
auto_increment自動增加計數器僅被存儲在主內存中,而不是存在磁盤上
MyISAM 須要全文索引,大批的inserts 語句在MyISAM下會快一些,count更快,快速寫入數據場景更適合;
3個構成文件,.frm文件存儲表定義,.MYD 數據文件,.MYI 索引文件
select count from tables, myisam直接讀系統結果表,很快
更好和更快的auto_increment處理;
五、數據庫表的一些修復方法
# shell 命令行下執行
mysqlcheck -uroot -p database test table -c test # myisamchk修復myisam存儲引擎的錯誤表,對innodb無效,必須在mysql服務中止後進行,-O參數設置各項參數內存大小; myisamchk -r tablename myisamchk –safe-recover tbl_name myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ... # innnodb的表修復,可經過修改表存儲引擎 導數據,再修改回來等方式 具體參考 【Innodb 表修復】http://www.cnblogs.com/zhoujinyi/archive/2013/05/10/3070667.html
【master-slave主從複製】
【配置數據庫的主從複製,此方案是 服務器對服務器,全部庫的任何變動都會同步到從庫上,新建庫,新建任何表等】
主從服務須要確保mysql版本一致;log-bin設成二進制日誌;server-id主從分別設成惟一值, #vi /etc/my.cnf [mysqld] log-bin=mysql-bin //[必須]啓用二進制日誌 server-id=222 //[必須]服務器惟一ID,默認是1,通常取IP最後一段,主服務器, server-id=223 //從服務器 分別重啓兩個mysql server。 【master服務器】 mysql > GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'q123456'; mysql > show master status +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 320 | | | | +------------------+----------+--------------+------------------+-------------------+ 【slave庫】 mysql > change master to master_host='192.168.52.101',master_user='mysync',master_password='q123456', master_log_file='mysql-bin.000001',master_log_pos=320;
【slave庫查看主從複製狀態】
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.52.101 Master_User: mysync Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 961 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 924 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 961 Relay_Log_Space: 1098 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 222 Master_UUID: 6be51420-bb89-11e6-99c1-000c29d16f0c Master_Info_File: /var/lib/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
【參考資料館】
監控mysql主從複製狀態的shell腳本 http://blog.formyz.org/?paged=6
centos6.5下安裝mysql http://www.linuxidc.com/Linux/2015-01/111413.htm
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++