本篇內(nèi)容主要給大家講解一下如何在linux下安裝MYSQL數(shù)據(jù)庫,并以安裝MYSQL5.6版本為例子教給大家進行登錄用戶名和密碼的修改等操作。
源碼下載地址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. 開始下載
操作系統(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
#默認情況下是安裝在/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編譯報錯需要刪除編譯緩存,修復(fù)錯誤后再次重新編譯
rm -f CMakeCache.txt
3.make make install
注意事項:
重新編譯時,需要清除舊的對象文件和緩存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
4.改變數(shù)據(jù)存儲目錄所有者為mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mydata
5.啟動腳本初始化數(shù)據(jù)庫
cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mydata
6.注冊服務(wù)
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#使用默認配置文件
cp support-files/my-default.cnf /etc/my.cnf
#讓chkconfig管理mysql服務(wù)
chkconfig --add mysqld
#開機啟動
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)過實際測試innodb_file_per_table = ON這條參數(shù)需要innodb_file_per_table = 1 才能生效,具體可以通過
mysql> show variables like '%per_table%';來查詢
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
默認密碼為空
9修改 vi /etc/security/limits.conf,然后加入以下內(nèi)容,退出再重新登陸即可(不需要重啟,退出當(dāng)前的連接shell即可)
# ulimit -n 查看參數(shù)是否生效
* hard nofile 655350
* soft nofile 655350
否則報錯如下:
錯誤#23: Out of resources when opening file './XX/USER.MYD' (Errcode: 24)
同時
vim /etc/security/limits.d/90-nproc.conf
刪除如下這行接觸centos對文件操作句柄的限制:
* soft nproc 1024
關(guān)于mysql的啟動和停止
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
查看mysql是否已經(jīng)啟動成功
ps -elf |grep mysql |grep -v grep
更改允許IP訪問(進入 mysql:2.使用 mysql庫:3.查看用戶表 :4.更新用戶表 :5.強制刷新權(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ù)庫登錄用戶密碼 可使用navcat客戶端連接進去更改登錄用戶的密碼
# mysql -uroot -p
Enter password: 【原始安裝默認密碼空直接回車】
mysql>use mysql;
mysql> update user set password=passworD("root") where user='root';
mysql> flush privileges;
mysql> exit;
使用客戶端連接測試之前一定要開放防火墻3306的連接端口
vi /etc/sysconfig/iptables
在22端口之后即可
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重啟防火墻即可生效
service iptables restart
您可能感興趣的文章:- Linux下rpm、yum和源碼三種安裝方式詳細介紹
- Linux下安裝mysql的方式(yum和源碼編譯兩種方式)
- linux下源碼安裝mysql5.6.20教程
- Linux CentOS 7源碼編譯安裝PostgreSQL9.5
- Linux CentOS6.6系統(tǒng)中安裝mysql源碼包的方法
- Linux下mysql源碼安裝筆記
- Linux下源碼編譯安裝配置SVN服務(wù)器的步驟分享
- SUSE Linux下源碼編譯方式安裝MySQL 5.6過程分享
- Linux+php+apache+oracle環(huán)境搭建之CentOS下源碼編譯安裝PHP
- 分析Linux內(nèi)核調(diào)度器源碼之初始化