1. 程式人生 > >mysql5.6安裝

mysql5.6安裝

star glibc 文件的 chown init.d dex rc.local 模版 主配置文件


wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
wget http://clientdown.xbsafe.cn/download/mysql/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

1、前期準備

安裝依賴包:
yum install -y gcc gcc-c++ makezlib zlib-devel pcre* libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers bison
增加用戶,創建要用的目錄:
groupadd mysql
useradd -r -g mysql mysql
mkdir -p /disk/mysql/src/
chmod +w /disk/mysql/src/
chown -R mysql:mysql /disk/mysql/src
mkdir -p /etc/mysql
mkdir -p /disk/mysql
mkdir -p /disk/mysql/data/
mkdir -p /disk/mysql/log/
mkdir -p /disk/mysql/binlog/
mkdir -p /disk/mysql/relaylog/
mkdir -p /disk/mysql/tmp
mkdir -p /disk/mysql/redologs
chown -R mysql:mysql /disk/mysql/

環境變量:
export PATH="$PATH:/disk/redis/bin"
export PATH="$PATH:/disk/mysql/src/bin"
export PATH="$PATH:/disk/mysql3306/src/bin"
export PATH="$PATH:/disk/mysql3307/src/bin"

2、解壓mysql


tar zxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
#將目錄直接copy到/usr/local目錄下
mv mysql-5.6.26-linux-glibc2.5-x86_64 /disk/mysql/src/mysql


3、配置


在源碼目錄下support-files目錄裏有很多配置文件的模版
#拷貝主配置文件
vim /etc/my.cnf
#初始化mysql
cd /disk/mysql/src/mysql
./scripts/mysql_install_db --defaults-file=/etc/my.cnf
#創建啟動腳本,cp後可以使用/etc/init.d/mysqld start啟動
cp /disk/mysql/src/mysql/support-files/mysql.server /etc/init.d/mysqld
#修改權限
chmod 755 /etc/init.d/mysqld

多實例啟動:
1) /disk/mysql/src/bin/mysqld --defaults-file=/etc/my.cnf &
2) /disk/mysql/src/bin/mysqld_safe --defaults-file=/etc/my.cnf &

/disk/mysql3306/src/mysql/bin/mysqld --defaults-file=/etc/mysql/my3306.cnf &
/disk/mysql3307/src/mysql/bin/mysqld --defaults-file=/etc/mysql/my3307.cnf &


初始登錄方法:
1)mysql -h 127.0.0.1 -uroot -P 3307
2)mysqladmin -S /tmp/mysql3307.sock

多實例關閉:
1) /disk/mysql/src/bin/mysqladmin -S /tmp/mysql.sock shutdown ---推薦
1) /disk/mysql/src/bin/mysqladmin -h 127.0.0.1 -uroot -P 3306 -p

#修改權限
chmod 755 /etc/init.d/mysqld3307
#如果是rhel或者centos系統的話自啟動文件/etc/rc.local
vim /etc/rc.local
/etc/init.d/mysqld3307 start

4、啟動mysql


/etc/init.d/mysqld start

進入mysql,以下語句設置root密碼刪除沒用的用戶
/disk/mysql/src/bin/mysqladmin -u root password $mysqlrootpwd
use mysql;
update user set password=password(‘newpassword‘) where user=‘root‘;
delete from user where not (user=‘root‘) ;
delete from user where user=‘root‘ and password=‘‘;
drop database test;
DROP USER ‘‘@‘%‘;
flush privileges;
#mysql的一些安全設置
mysql_secure_installation

#mysql錯誤文件的位置
/usr/local/webserver/mysql/data/localhost.err

啟動時的兩個問題:
l啟動報錯:File‘./mysql-bin.index‘ not found (Errcode: 13)
解決辦法:
一般就是權限問題,mysql用戶是否對數據庫目錄內的所有文件具有寫的權限
chown mysql.mysql -R data

l啟動報錯:0911029:10:22 [ERROR] Can‘t open the mysql.plugin table. Please run mysql_upgrade tocreate it.
解決辦法:
 出現這種問題是因為沒有指定mysql安裝目錄和data目錄導致的,運行如下命令:
# /usr/local/mysql/scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

mysql5.6安裝