2014年10月27日 星期一

Arch使用MySQL原始碼安裝MySQL

因為 http://carlislebear.blogspot.jp/2014/10/install-schema-sync.html 這篇的關係,所以打算把MariaDB移除,手動安裝MySQL

參考連結:
http://shaurong.blogspot.jp/2014/08/mysql-5620targz-centos-70-x8664.html
http://blog.sina.com.cn/s/blog_606a23dd0101g1wr.html

0. 安裝cmake ( 自mysql5.5及以上的源程序包,不再包括configure文件,因此不能直接安装,需要使用cmake来进行安装 )
用pacman 直接安裝或上網找 cmake-xxx.pkg.tar.xz 下來再用pacman裝

1. 到MySQL官網下載MySQL Community Server 
Select Platform: 選擇Source Code

下載最下面的壓縮檔,mysql-5.6.21.tar.gz,並放到/usr/local/src下解壓縮,解壓縮出來要有 CMakeCache.txt 檔才對,INSTALL-SOURCE 4823行左右也有安裝教學

# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz #我解壓縮到/usr/local/src
shell> cd mysql-VERSION
shell> cmake .
shell> make #這步會很久,所花時間是用pacman、apt-get等管理工具不能比的
shell> make install #也很久
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

mysql指令找不到
# which mysql
which: no mysql in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl)
解法1:
將/usr/local/mysql/bin/mysql 用ln -fs 到/usr/local/bin 去
# cd /usr/local/bin
# ln -fs /usr/local/mysql/bin/mysql
# ln -fs /usr/local/mysql/bin/mysqldump
# ln -fs /usr/local/mysql/bin/mysqladmin
解法2:
設定環境變數(未測試)

安裝後用mysql -u root -p 登錄出現錯誤:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解法:
指定登錄位置
mysql -u root -p -h 127.0.0.1

啟用mysql 服務
# /usr/local/mysql/bin/mysqld_safe &
查mysql啟動時的錯誤
# tail -f /usr/local/mysql/data/your_pc_name.err
出現錯誤:
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
解法:
(中間下過這些指令,不確定要不要做:
# chmod 777 /usr/local/mysql/support-files/mysql.server
# chown -R mysql:mysql /usr/local/mysql/
)
# /usr/local/mysql/scripts/mysql_install_db --user=mysql
可能當初在裝mysql時,沒有停用原本的MariaDB再裝,造成這句沒有執行成功,執行成功的畫面:
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h lmannb password 'new-password'

Alternatively you can run:

  ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.  

在此之前試過 # ./mysql_upgrade -u root -p => 無效

檢查mysql有沒有跑起來:
# ps aux | grep mysql
mysql     4649  3.5  5.6 967604 456952 pts/3   Sl   19:58   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/lmannb.err --pid-file=/usr/local/mysql/data/lmannb.pid

沒有留言:

張貼留言