程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> mysql 編譯安裝筆記

mysql 編譯安裝筆記

編輯:關於MYSQL數據庫

安裝環境
本次安裝MySQL的操作系統選用CentOS5.2,mysql選擇5.1.31版本。由於現在的MySQL被
sun收購,下載免費版本的MySQL需要注冊,很麻煩,直接到
搜索最新的穩定版本下載即可。

wget FTP://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.1/MySQL-5.1.31.tar.gz

解壓 # tar -xvzf msyql-5.1.31.tar.gz # ./configure --prefix=/usr/local/MySQL --enable-assembler --with-extra-charsets=complex --enable-thread-safe-clIEnt --with-big-tables --with-plugins=partition,innobase,myisam,ndbcluster,blackhole --with-charset=utf8 --with-readline --with-ssl --with-embedded-server --enable-local-infile
# make && make install

將MySQL的lib文件加載到系統變量中
# vi /etc/ld.so.conf
/usr/local/mysql/lib/MySQL
# ldconfig -v | grep mysql /usr/local/mysql/lib/MySQL:
        libmysqlclIEnt.so.16 -> libMySQLclIEnt.so.16.0.0
        libmysqlclIEnt_r.so.16 -> libMySQLclIEnt_r.so.16.0.0

顯示上面信息代表系統加載MySQL的lib庫正常

創建MySQL用戶
# useradd -s /sbin/nologin -c 'mysql user' MySQL

將安裝目錄權限修改為MySQL
# chown -R mysql.mysql /usr/local/MySQL

將對應的配置文件復制到/etc/目錄下
# cd /usr/local/mysql/share/MySQL
# cp my-large.cnf /etc/my.cnf

編輯my.cnf文件,配置相關參數,結果如下所示: [clIEnt]
port            = 3306
socket          = /home/mysql/MySQL.sock

[MySQLd]
port            = 3306
socket          = /home/mysql/MySQL.sock
datadir         = /home/MySQL              # 數據庫存放目錄
skip-locking
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8

log-bin=/home/mysql/MySQL-bin # 二進制日志文件的絕對路徑
binlog-do-db=gamedb            # 需要記錄二進制日志的數據庫
binlog_format=mixed            # bin log的記錄模式。建議使用mixed

log-error=/home/MySQL/error.log
pid-file=/home/mysql/MySQL.pid

server-id       = 10

[MySQLdump]
quick
max_allowed_packet = 16M

[MySQL]
no-auto-rehash

[isamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[MySQLhotcopy]
interactive-timeout

生成默認數據庫
# /usr/local/mysql/bin/MySQL_install_db

將默認數據庫的權限修改為MySQL
# cd /home/
# chown -R mysql.mysql MySQL

安裝完畢收尾工作
# cd /usr/local/bin
# ln -s /usr/local/MySQL/bin/* .
# cd /usr/local/libexec
# ln -s /usr/local/MySQL/libexec/* .
# cd /usr/share/man/man1
# ln -s /usr/local/MySQL/share/man/man1/* .
# cd ../man8
# ln -s /usr/local/MySQL/share/man/man8/* .

將MySQL作為系統服務隨系統啟動
# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/MySQLd
# chkconfig --add MySQLd
# chkconfig MySQLd on

啟動MySQL
# mysqld_safe & # service MySQLd start

如果報錯,查看/home/MySQL/error.log文件排查問題

基本的MySQL安全設置
安裝完mysql後,其bin目錄下有一個mysql_secure_installation 腳本,用來設置MySQL
最基本的安全選項,其做了如下操作:

(1)設置本地root用戶登陸的密碼(默認情況下本地root登陸是不需要密碼的)
(2)刪除anonymous 匿名用戶
(3)禁止ront遠程訪問數據庫
(4)刪除默認test數據庫,這個數據庫也沒什麼用只是測試anonymous 用戶登陸之用。
(5)這一步是最後一步,更新權限表,然後退出。

操作步驟如下所示:
# cd /usr/local/MySQL/bin
# ./MySQL_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
passWord for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the passWord will be blank,
so you should just press enter here.

Enter current passWord for root (enter for none): # 這一步輸入當前root密碼默認空,回車即可
OK, successfully used passWord, moving on...

Setting the root passWord ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root passWord? [Y/n] Y   # 是否設置root密碼
New passWord:      # 設置root密碼
Re-enter new passWord:    
PassWord updated successfully!
Reloading privilege tables..
... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y # 是否移除匿名用戶
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root passWord from the network.

Disallow root login remotely? [Y/n] Y # 是否禁止root遠程訪問
... Success!

By default, MySQL comes with a database named 'test' that anyone can
Access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and Access to it? [Y/n] Y # 是否刪除test數據庫
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y # 是否更新權限表,如果不更新則前面的操作都無效
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

查看數據目錄下的文件
ll /home/mysql -rw-rw---- 1 MySQL root      2041 Feb 12 16:57 error.log
-rw-rw---- 1 mysql MySQL 10485760 Feb 12 16:56 ibdata1
-rw-rw---- 1 mysql MySQL 5242880 Feb 12 16:57 ib_logfile0
-rw-rw---- 1 mysql MySQL 5242880 Feb 12 15:29 ib_logfile1
drwx------ 2 mysql mysql     4096 Feb 12 15:27 MySQL
-rw-rw---- 1 mysql mysql    18902 Feb 12 15:27 MySQL-bin.000001
-rw-rw---- 1 mysql mysql   704189 Feb 12 15:27 MySQL-bin.000002
-rw-rw---- 1 mysql mysql      125 Feb 12 15:33 MySQL-bin.000003
-rw-rw---- 1 mysql mysql      125 Feb 12 16:49 MySQL-bin.000004
-rw-rw---- 1 mysql mysql      125 Feb 12 16:56 MySQL-bin.000005
-rw-rw---- 1 mysql mysql      125 Feb 12 16:56 MySQL-bin.000006
-rw-rw---- 1 mysql mysql      106 Feb 12 16:57 MySQL-bin.000007
-rw-rw---- 1 mysql mysql      203 Feb 12 16:57 MySQL-bin.index
-rw-rw---- 1 mysql mysql        6 Feb 12 16:57 MySQL.pid
srwxrwxrwx 1 mysql mysql        0 Feb 12 16:57 MySQL.sock
drwx------ 2 mysql MySQL     4096 Feb 12 15:27 test

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved