linux下安裝mysql數(shù)據(jù)庫(kù)5.6源碼安裝,修改登錄用戶密碼
本篇內(nèi)容主要給大家講解一下如何在linux下安裝MYSQL數(shù)據(jù)庫(kù),并以安裝MYSQL5.6版本為例子教給大家進(jìn)行登錄用戶名和密碼的修改等操作。
源碼下載地址http://dev.mysql.com/downloads/mysql/5.6.html#downloads
tar.gz地址:https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz
選擇Generic Linux (Architecture Independent), Compressed TAR Archive
選擇 No thanks, just start my download. 開(kāi)始下載
操作系統(tǒng):
centos6.5 x86_64
一、yum安裝相關(guān)依賴
# yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake bison git openssl openssl-devel
二、編譯安裝
1.添加用戶
groupadd mysql
useradd -r -g mysql mysql
2.編譯安裝
tar xf mysql-5.6.34.tar.gz
cd mysql-5.6.34
#默認(rèn)情況下是安裝在/usr/local/mysql
# cmake編譯參數(shù)可以自己調(diào)整
************************************************************** -- Looking for asprintf -- Looking for asprintf - found -- Check size of pthread_t -- Check size of pthread_t - done -- Using cmake version 2.8.12.2 -- Not building NDB -- Performing Test HAVE_PEERCRED -- Performing Test HAVE_PEERCRED - Success -- Library mysqlclient depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl -- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source. -- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 -- Library mysqlserver depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl;crypt -- CMAKE_BUILD_TYPE: RelWithDebInfo -- COMPILE_DEFINITIONS: HAVE_CONFIG_H -- CMAKE_C_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement -- CMAKE_CXX_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: WITH_READLINE -- Build files have been written to: /root/mysql-5.6.34
**************************************************************
cmake編譯報(bào)錯(cuò)需要?jiǎng)h除編譯緩存,修復(fù)錯(cuò)誤后再次重新編譯
rm -f CMakeCache.txt
3.make && make install
注意事項(xiàng):
重新編譯時(shí),需要清除舊的對(duì)象文件和緩存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
4.改變數(shù)據(jù)存儲(chǔ)目錄所有者為mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mydata
5.啟動(dòng)腳本初始化數(shù)據(jù)庫(kù)
cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mydata
6.注冊(cè)服務(wù)
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#使用默認(rèn)配置文件
cp support-files/my-default.cnf /etc/my.cnf
#讓chkconfig管理mysql服務(wù)
chkconfig --add mysqld
#開(kāi)機(jī)啟動(dòng)
chkconfig mysqld on
編輯 vi /etc/my.cnf配置,加入以下內(nèi)容
innodb_file_per_table = 1
datadir = /data/mydata
log-bin=/data/binlogs/mysql-bin
注意:
經(jīng)過(guò)實(shí)際測(cè)試innodb_file_per_table = ON這條參數(shù)需要innodb_file_per_table = 1 才能生效,具體可以通過(guò)
mysql> show variables like '%per_table%';來(lái)查詢
mkdir /data/binlogs
chown -R mysql.mysql /data/binlogs
8.將mysql命令加入環(huán)境變量中
vim /etc/profile.d/mysql.sh
加入
export PATH=/usr/local/mysql/bin:$PATH
默認(rèn)密碼為空
9修改 vi /etc/security/limits.conf,然后加入以下內(nèi)容,退出再重新登陸即可(不需要重啟,退出當(dāng)前的連接shell即可)
# ulimit -n 查看參數(shù)是否生效
* hard nofile 655350
* soft nofile 655350
否則報(bào)錯(cuò)如下:
錯(cuò)誤#23: Out of resources when opening file './XX/USER.MYD' (Errcode: 24)
同時(shí)
vim /etc/security/limits.d/90-nproc.conf
刪除如下這行接觸centos對(duì)文件操作句柄的限制:
* soft nproc 1024
關(guān)于mysql的啟動(dòng)和停止
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
查看mysql是否已經(jīng)啟動(dòng)成功
ps -elf |grep mysql |grep -v grep
更改允許IP訪問(wèn)(進(jìn)入 mysql:2.使用 mysql庫(kù):3.查看用戶表 :4.更新用戶表 :5.強(qiáng)制刷新權(quán)限 :)
/usr/local/mysql/bin/mysql -u root -p
use mysql;
SELECT `Host`,`User` FROM user;
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
flush privileges;
更改mysql數(shù)據(jù)庫(kù)登錄用戶密碼 可使用navcat客戶端連接進(jìn)去更改登錄用戶的密碼
# mysql -uroot -p
Enter password: 【原始安裝默認(rèn)密碼空直接回車】
mysql>use mysql;
mysql> update user set password=passworD("root") where user='root';
mysql> flush privileges;
mysql> exit;
使用客戶端連接測(cè)試之前一定要開(kāi)放防火墻3306的連接端口
vi /etc/sysconfig/iptables
在22端口之后即可
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重啟防火墻即可生效
service iptables restart
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。