日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql5.5.30源码安装及主从搭建

發布時間:2024/1/17 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql5.5.30源码安装及主从搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

雙機熱備(實驗環境)

主服務器:ip地址192.168.100.244,mysql版本5.5.30,源碼安裝 從服務器:ip地址192.168.100.245

一、源碼安裝mysql5.5

啟動目錄:/usr/local/mysql 數據文件目錄:/data/mysql 二進制日志目錄:/data/mysql/binlog 1.添加mysql 用戶(不添加用戶目錄) shell> groupadd mysql shell> useradd -r -g mysql mysql -g, --gid GROUP The group name or number of the user’s initial login group. The group name must exist. A group number must refer to an?already?existing group. ?/etc/default/useradd. -r ?This flag is used to create a system account. That is, a user with a UID lower than the value of UID_MIN defined in?/etc/login.defs and whose password does not expire. Note that useradd will not create a home directory for such an user,?regardless of the default setting in /etc/login.defs. You have to specify -m option if you want a home directory for a?system?account to be created. This is an option added by Red Hat ps: # yum install gcc-c++ # yum install cmake` # yum install -y ncurses-devel 2.編譯和安裝 shell> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DDEFAULT_CHARSET=latin1 \-DDEFAULT_COLLATION=latin1_swedish_ci\-DENABLED_LOCAL_INFILE=ON \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \-DWITH_COMMENT="jss edition" \-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \-DSYSCONFDIR=/data/mysql/ shell> make shell> make test shell> make install

?-DCMAKE_INSTALL_PREFIX=/usr/local/mysql? ??指定啟動目錄存放路徑

-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock?? ? 指定sock存放路徑 -DSYSCONFDIR=/data/mysql/? ? 指定數據庫文件存放位置 3.部分機器需要安裝cmake[cmake-2.8.12.2.tar.gz] shell> yum install ncurses-devel shell> yum install bison shell > yum install gcc* shell> ./bootstrap --prefix=/usr/local/cmake shell> make shell> make install

?4.修改數據目錄權限

shell> chown -R mysql:mysql mysql/ 5.導入數據庫文件 cd /usr/local/mysql/ ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ 6.添加mysql服務 cd /usr/local/mysql/support-files/ cp -rp mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 345 mysqld on 7.修改配置文件 [client] port = 3306 socket = /data/mysql/mysql.sock default_character-set=utf8[mysqld] port = 3306 socket = /data/mysql/mysql.sock character_set_server=utf8 log-error=/data/mysql/log/error.log datadir=/data/mysql/data/ max_connections = 16384 table_cache = 64slow_query_log_file=/data/mysql/mysql-slow.log long_query_time=3symbolic-links=0skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M expire_logs_days = 1 log-bin=/data/mysql/binlog/mysql-bin binlog_format=STATEMENT server-id = 2 innodb_buffer_pool_size = 16M innodb_additional_mem_pool_size = 2M innodb_log_file_size = 5M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 innodb_file_per_table=1 innodb_flush_method = O_DIRECT innodb_file_io_threads = 4innodb_data_home_dir=/data/mysql/data innodb_data_file_path=ibdata1:1G:autoextend

8.啟動mysqld服務

/etc/init.d/mysqld start 9.添加/usr/local/mysql/bin 到PATH 在/etc/profile最后一行添加:export $PATH="$PATH:/usr/local/mysql/bin" 保存退出,執行shell> source /etc/profile 10.設置mysql密碼 mysqladmin -u root password "newpassword"

二、主從配置

1.主服務器bin-log配置 log-bin=/data/mysql/binlog/mysql-bin expire_logs_days=1 可選配置: binlog-do-db=fire binlog-ignore-db=mysql #這個最好不要添加,因為存儲過程都是存在msyql庫的proc表里 2.主庫新建從庫賬戶 grant replication slave on *.* to 'slave-user1'@'192.168.1.72' identified by 'redhat'; flush privileges; 3.關閉主服務器mysql表寫入,dump數據庫 3.1先查詢當前正在執行的操作是否結束:show processlist; 3.2 在所有操作執行完后, flush tables with read lock; 讀master進程狀態:mysql > show master status \G 此時,lock表的終端不要關閉,因為關閉會導致數據庫解鎖。 開啟另外一個終端,dump數據庫:# mysqldump -uroot -p --opt -R -B -F --databases fire | gzip > db.tar.gz --opt?--add-drop-table + --add-locks + --create-options + --disables-keys + --extended-insert + --lock-tables + --quick + --set+charset -R?在轉儲的數據庫中轉儲存儲程序(函數和程序)。使用---routines產生的輸出包含CREATE PROCEDURE和CREATE FUNCTION語句以重新創建子程序。但是,這些語句不包括屬性,例如子程序定義者或創建和修改時間戳。這說明當重載子程序時,對它們進行創建時定義者應設置為重載用戶,時間戳等于重載時間。

如果你需要創建的子程序使用原來的定義者和時間戳屬性,不使用--routines。相反,使用一個具有mysql數據庫相應權限的MySQL賬戶直接轉儲和重載mysql.proc表的內容。

該選項在MySQL 5.1.2中添加進來。在此之前,存儲程序不轉儲。

-B?轉儲幾個數據庫。通常情況,mysqldump將命令行中的第1個名字參量看作數據庫名,后面的名看作表名。使用該選項,它將所有名字參量看作數據庫名。CREATE DATABASE IF NOT EXISTS db_name和USE db_name語句包含在每個新數據庫前的輸出中。 -F?始轉儲前刷新MySQL服務器日志文件。該選項要求RELOAD權限。請注意如果結合--all--database(或-A)選項使用該選項,根據每個轉儲的數據庫刷新日志。例外情況是當使用--lock-all-tables或--master-data的時候:在這種情況下,日志只刷新一次,在所有 表被鎖定后刷新。如果你想要同時轉儲和刷新日志,應使用--flush-logs連同--lock-all-tables或--master-data。 對主庫解鎖:unlock tables; 打包 # tar -zcf fire.tar.gz ./fire.sql 復制到從服務器 4.配置從服務器master、開啟slave進程 mysql> change master to ?master_host='192.168.100.252', master_user='slave-user1', master_password='1234',?? ??? ??? ??? ??? ??? ??? ? ??? ??? ?? master_log_file='mysql-bin.000001', master_log_pos=479; 解壓主服務器的fire庫 # tar -xvf fire.tar.gz? 在主服務器添加fire數據庫 mysql > create database fire ; 附加數據到fire庫 # mysql -uroot -p fire < fire.sql 開slave進程 mysql > start slave ; mysql > show slave status ; 5.開啟主服務器mysql表寫入,查看從服務器的slave進程狀態 mysql > show master status ;

三、后期維護

1.二進制日志過多的時候,用sql語句刪除過多的日志 mysql> purge binary logs to 'mysql-bin.000128'; Query OK, 0 rows affected (2.92 sec) 將二進制日志刪除到000128 直接進數據庫查看purge_binary_logs的屬性值,通過set purge_binary_logs=2來設置 2.主從服務器服務重啟順序 3.mysqldump對數據庫版本的要求 一鈡情況會出現mysqldump 數據報錯 mysqldump: Couldn't execute 'SET OPTION SQL_QUOTE_SHOW_CREATE=1': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_QUOTE_SHOW_CREATE=1' at line 1 (1064) 參考網上較多的解決方案: 1)使用與mysql server相同版本的mysqldump的絕對路徑進行dump,如:/usr/bin/mysqldump -uroot -p databasename > sql.sql? 2)核對數據庫版本(server版本和client版本),低client版本不能導出高server版本的數據庫(如5.5的mysqldump不能導出5.6的server的數據) 4. 從庫配置好master后,啟動slave,報錯: Slave_IO_Running: Yes Slave_SQL_Running: No Last_Error: Error 'Duplicate entry '11531105-356' for key 1' on query. Default database: 'db_bayu_5'. Query: 'INSERT INTO `t_quest`SET`rid`=11531105,`quest_id`=356,`type`=0,`status`=1,`target_idx`=0,`quest_loop`=0,`progress`='',`entrust`=2,`star`=0,`money_type`=0,`left_count`=1,`last_round_date`=1405642337' 分析:配置的從庫和mysqldump的時間不協調,出現了很多redo錯誤 5. error.log 140827 10:04:41 ?InnoDB: ERROR: the age of the last checkpoint is 9433834, InnoDB: which exceeds the log group capacity 9433498. InnoDB: If you are using big BLOB or TEXT rows, you must set the InnoDB: combined size of log files at least 10 times bigger than the InnoDB: largest such row.

At first glance, I would say that your innodb_log_file_size is way too small. It should be bigger to do two things:

  • Accommodate any big BLOB or TEXT fields
  • Holding bigger transactions

Here is what you should do for now to see if it helps:

STEP 01) Change the following in /etc/my.cnf

[mysqld]innodb_log_buffer_size??????????=?32M innodb_buffer_pool_size ??? ??? ??? ??=?3G innodb_log_file_size ? ? ? ? ??=?768M

STEP 02)?service mysql stop

STEP 03)?rm -f /var/lib/mysql/ib_logfile*

STEP 04)?service mysql start

This will rebuild the following files

  • /var/lib/mysql/ib_logfile0
  • /var/lib/mysql/ib_logfile1

Give it a Try !!!

轉載于:https://www.cnblogs.com/forilen/p/4271778.html

總結

以上是生活随笔為你收集整理的mysql5.5.30源码安装及主从搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。