linux安裝mysql-5.6.26
檢視工具:winscp
下載地址
http://mirrors.sohu.com/mysql/MySQL-5.6/
檔案: mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
解壓
tar -xzf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
注:安裝目錄需要設定到解壓目錄,否則報以下錯誤
FATAL ERROR: Could not find ./bin/my_print_defaults If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation. If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location.
or
FATAL ERROR: Could not find my-default.cnf If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation. If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location.
將解壓的目錄放到/usr/local下改為mysql或新增軟連線
mv mysql-5.6.26-linux-glibc2.5-x86_64 mysql
or
ln -s /www/mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql
增加mysql使用者和組
groupadd mysql useradd -r -g mysql mysql
修改mysql目錄及子檔案屬主和屬組
chown -R mysql:mysql mysql
進入mysql目錄並安裝
cd mysql scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
安裝過程可能缺少某些檔案,一般用 yum install -y xxx 按需安裝即可.
實現使用 service mysqll (start|status|stop) 命令操作mysql.
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
錯誤:
[root@localhost mysql]# mysql -bash: mysql: command not found
解決:配置環境變數,把 export PATH=$PATH:/usr/local/mysql/bin新增到 /etc/profile中, source /etc/profile重新載入環境變數, service mysql start啟動mysql服務。
錯誤:
[root@localhost mysql]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解決:
mysql --socket=/var/lib/mysql/mysql.sock ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
啟動成功
mysql> select version(); +-----------+ | version() | +-----------+ | 5.6.26 | +-----------+ 1 row in set (0.00 sec)
成功後可能需要往mysql的user表增加新賬號
錯誤:指定了嚴格模式,為了安全,嚴格模式禁止通過insert 這種形式直接修改mysql庫中的user表進行新增新使用者
1364 - Field 'ssl_cipher' doesn't have a default value
解決:
vim /usr/local/mysql/my.cnf
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 改為 sql_mode=NO_ENGINE_SUBSTITUTION
修改密碼:
mysql>UPDATE user SET password=PASSWORD('1') where USER='root';
允許使用使用者名稱root密碼1從任何主機連線到mysql伺服器
該建立的root賬號只是從外部訪問的賬號,與內部linux訪問該mysql時所用root不同,內部linux訪問該mysql的root賬號也不是linux的系統root賬號
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1' WITH GRANT OPTION;
重新整理許可權
mysql>FLUSH PRIVILEGES;
MySql提示:The server quit without updating PID file(…)失敗
可能程式裡已經存在mysql程式
解決方法:用命令“ps -ef|grep mysqld”檢視是否有mysqld程式,如果有使用“kill -9 程式號”殺死,然後重新啟動mysqld!
檢視CentOS linux版本: cat /etc/issue
root@DB-02 ~]# mysql -u root
-bash: mysql: command not found
原因:這是由於系統預設會查詢/usr/bin下的命令,如果這個命令不在這個目錄下,當然會找不到命令,我們需要做的就是對映一個連結到/usr/bin目錄下,相當於建立一個連結檔案。
首先得知道mysql命令或mysqladmin命令的完整路徑,比如mysql的路徑是:/usr/local/mysql/bin/mysql,我們則可以這樣執行命令:
# ln -s /usr/local/mysql/bin/mysql /usr/bin