Mysql-5.5.13安裝配置

由於Mysql的開源與免費,在PRD環境能夠很穩定的運行,性能也很好,使其獲得了很大的應用;同時mysql也在不間斷的推出新的版本;
以下爲Mysql-5.5.13的安裝配置;
環境:
    OS Version:Red Hat Enterprise Linux Server release 6.0 (Santiago)
    Kernel Version:2.6.32-71.el6.x86_64
    Mysql Version:mysql-5.5.13.tar.gz

安裝環境部署

  1. 系統依賴包檢查

gcc gcc-c++ autoconf automake zlib-devel libxml2-devel ncurses-devel libmcrypt* libtool*(libtool-ltdl-devel*) cmake
需要安裝以上系統依賴包才能順利的完成mysql的安裝;camke包爲編譯mysql使用(不是經典的confiure了)

  1. mysql環境配置

  •  mysql用戶創建

# id mysql

如果沒有結果,新建mysql賬號

# useradd -u xxx -s /sbin/nologin mysql (限制mysql用戶遠程登錄系統的權限)

# id mysql

uid=503(mysql) gid=503(mysql) =503(mysql)

確定mysql用戶已經建立OK

  • 創建data數據存放目錄

# mkdir /mysqldata/data

# chown –R mysql:mysql /mysqldata

  1. 編譯安裝mysql

  • 獲取mysql源碼包

通過以下路徑下載mysql-5.5.13.tar.gz,也可在http://www.mysql.com/downloads/mysql官網網站進行下載

  • 編譯安裝

# tar zxvf mysql-5.5.13.tar.gz

# cd mysql-5.5.13

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_DATADIR=/mysqldata/data

# make

# make install

編譯安裝完成以後,檢查mysql安裝是否已經安裝成功;

在編譯安裝的過程中,可能會出現一些異常,主要的原因還是系統的依賴包沒有安裝上去,編譯安裝mysql之前,一定要把上述提到的包全部安裝;

比如這個錯誤:

mysqld.cc: In function ‘void handle_connections_sockets()’:

主要是沒有安裝libmcrypt相關的包

直接使用yum install libmcrypt* -y安裝完成後,在重新編譯

在編譯出現異常,在重新編譯的時候,需要先刪除mysql目錄下的CMakeCache.txt這個文件,然後再進行編譯!!!

# ll /usr/local/mysql

drwxr-xr-x.2 root root4096 11月 16 10:08 bin

-rw-r--r--.1 root root 179875月 11 2011 COPYING

drwxr-xr-x.4 root root4096 11月 16 10:08 data

drwxr-xr-x.2 root root4096 11月 16 10:08 docs

drwxr-xr-x.3 root root4096 11月 16 10:08 include

-rw-r--r--.1 root root73705月 11 2011 INSTALL-BINARY

drwxr-xr-x.3 root root4096 11月 16 10:08 lib

drwxr-xr-x.4 root root4096 11月 16 10:08 man

drwxr-xr-x. 10 root root4096 11月 16 10:08 mysql-test

-rw-r--r--.1 root root25525月 11 2011 README

drwxr-xr-x.2 root root4096 11月 16 10:08 scripts

drwxr-xr-x. 27 root root4096 11月 16 10:08 share

drwxr-xr-x.4 root root4096 11月 16 10:08 sql-bench

drwxr-xr-x.2 root root 4096 11月 16 10:08 support-files

  1. 初始化mysql

# cd /usr/local/mysql/scripts

# ll mysql_install_db

-rwxr-xr-x. 1 root root 14453 11月 16 09:51 mysql_install_db

確認這個腳本有執行權限;

如果沒有,

# chmod +x mysql_install_db

# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysqldata/data/

--user=user_nameThe login username to use for running mysqld.(由於以後我們是通過mysql用戶去啓動mysql;

  1. 修改配置文件

# cp /usr/local/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf

並修改對應的參數,滿足需求;

以下是一些配置參考:

[client]

port= 3306

socket= /tmp/mysql.sock

[mysqld]

port= 3306

socket= /tmp/mysql.sock

datadir = /mysqldata/data (這個地方的datadir一定要與初始化數據庫的datadir一致)

back_log = 50

max_connections = 100

max_connect_errors = 10

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 1M

max_heap_table_size = 64M

read_buffer_size = 2M

read_rnd_buffer_size = 16M

sort_buffer_size = 8M

join_buffer_size = 8M

thread_cache_size = 8

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = INNODB

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 64M

log-bin=/logdata/binlog

binlog_format=mixed

slow_query_log

long_query_time = 2

server-id = 1

key_buffer_size = 32M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 1G

innodb_data_file_path = ibdata1:100M:autoextend

innodb_data_home_dir = /mysqldata/innodb/data

innodb_write_io_threads = 8

innodb_read_io_threads = 8

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 = 3

innodb_log_group_home_dir = /mysqldata/innodb/log

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 512M

sort_buffer_size = 512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 8192 

  1. 啓動測試mysql

# /usr/local/mysql/bin/mysqld_safe &

檢查日誌查看數據庫是否成功,第一次運行的日誌大致如下:

111116 13:50:38 mysqld_safe Starting mysqld daemon with databases from /mysqldata/data

111116 13:50:38 InnoDB: The InnoDB memory heap is disabled

111116 13:50:38 InnoDB: Mutexes and rw_locks use GCC atomic builtins

111116 13:50:38 InnoDB: Compressed tables use zlib 1.2.3

111116 13:50:38 InnoDB: Initializing buffer pool, size = 1.0G

111116 13:50:38 InnoDB: Completed initialization of buffer pool

InnoDB: The first specified data file /mysqldata/innodb/data/ibdata1 did not exist:

InnoDB: a new database to be created!

111116 13:50:38InnoDB: Setting file /mysqldata/innodb/data/ibdata1 size to 100MB

InnoDB: Database physically writes the file full: wait...

111116 13:50:38InnoDB: Log file /mysqldata/innodb/log/ib_logfile0 did not exist: new to be created

InnoDB: Setting log file /mysqldata/innodb/log/ib_logfile0 size to 256 MB

InnoDB: Database physically writes the file full: wait...

InnoDB: Progress in MB: 100 200

111116 13:50:41InnoDB: Log file /mysqldata/innodb/log/ib_logfile1 did not exist: new to be created

InnoDB: Setting log file /mysqldata/innodb/log/ib_logfile1 size to 256 MB

InnoDB: Database physically writes the file full: wait...

InnoDB: Progress in MB: 100 200

111116 13:50:43InnoDB: Log file /mysqldata/innodb/log/ib_logfile2 did not exist: new to be created

InnoDB: Setting log file /mysqldata/innodb/log/ib_logfile2 size to 256 MB

InnoDB: Database physically writes the file full: wait...

InnoDB: Progress in MB: 100 200

InnoDB: Doublewrite buffer not found: creating new

InnoDB: Doublewrite buffer created

InnoDB: 127 rollback segment(s) active.

InnoDB: Creating foreign key constraint system tables

InnoDB: Foreign key constraint system tables created

111116 13:50:46InnoDB: Waiting for the background threads to start

111116 13:50:47 InnoDB: 1.1.7 started; log sequence number 0

111116 13:50:48 [Note] Event Scheduler: Loaded 0 events

111116 13:50:48 [Note] /usr/local/mysql/bin/mysqld: ready for connections.

Version: '5.5.13-log'socket: '/tmp/mysql.sock'port: 3306Source distribution

紅色部分表示mysql已經啓動ok了,3306的端口也已經處於監聽狀態;

這時通過ps 查看進程,應該就能看到mysql的進程了!

# ps -ef | grep mysql | grep –v grep

# ps -ef | grep mysql | grep -v grep 

root22777 194770 13:50 pts/400:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe

mysql23426 227770 13:50 pts/400:00:04 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysqldata/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysqldata/data/test-file01.err --open-files-limit=8192 --pid-file=/mysqldata/data/test-file01.pid --socket=/tmp/mysql.sock --port=3306

 

MYSQL安全設置

  • root帳戶設置初始密碼

# /usr/local/mysql/bin/mysqladmin -u root password 'new-password'

或者限制只能通過本機登陸

# /usr/local/mysql/bin/mysqladmin -u root -h ‘hostname’ password 'new-password'

  • 刪除本機匿名連接的空密碼帳號

本機登錄mysql

mysql>use mysql; //選擇默認數據庫mysql

mysql>update user set password=’root123’ where user = '127.0.0.1';

mysql>delete from user where password="";//不允許root密碼爲空

mysql>flush privileges;

  • 容許root用戶是遠程登錄

對於root賬號,如果考慮安全應該新建其他賬號用於遠程登錄,root賬號可以不必開啓遠程登錄。不過對於一般使用,沒有太多安全需求,允許root用戶遠程登錄可以方便管理,畢竟使用專用管理軟件的圖形界面在操作方面要方便的多。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章