環(huán)境準(zhǔn)備
主機(jī)名稱 | IP地址 |
---|---|
mysql | 192.168.200.9 |
echo "192.168.200.9 mysql ">>/etc/hosts
- 操作系統(tǒng)信息
[root@hadoop-master ~]# uname -r
2.6.32-358.el6.x86_64
[root@hadoop-master ~]# uname -m
x86_64
[root@hadoop-master ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)
[root@hadoop-master ~]# getenforce
Disabled
創(chuàng)建MySQL用戶
useradd mysql -s /sbin/nologin -M
id mysql
安裝MySQL
- 下載
MySQL下載地址
下載慢,可以使用迅雷下載 - 安裝
tar zxvf mysql-5.5.54-linux2.6-x86_64.tar.gz
mkdir /application
mv mysql-5.5.54-linux2.6-x86_64 /application/mysql-5.5.54
ln -s /application/mysql-5.5.54/ /application/mysql
ll /application/
chown -R mysql:mysql /application/mysql*
初始化數(shù)據(jù)庫(kù)
[root@mysql mysql]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
初始化信息:
Installing MySQL system tables...
170903 15:54:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
170903 15:54:08 [Note] /application/mysql/bin/mysqld (mysqld 5.5.54) starting as process 3137 ...
OK
Filling help tables...
170903 15:54:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
170903 15:54:08 [Note] /application/mysql/bin/mysqld (mysqld 5.5.54) starting as process 3144 ...
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:
/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h mysql password 'new-password'
Alternatively you can run:
/application/mysql/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 /application/mysql ; /application/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
修改數(shù)據(jù)庫(kù)配置文件
mysql默認(rèn)配置文件是/etc/my.cnf,備份原有的
mv /etc/my.cnf /etc/my.cnf.default-backup
使用較小的配置:
[root@mysql support-files]# cp /application/mysql/support-files/my-small.cnf /etc/my.cnf
啟動(dòng)MySQL
修改啟動(dòng)mysql腳本
由于二進(jìn)制默認(rèn)安裝目錄在/usr/local下及皂,而我們將自定義將mysql安裝在/application/下宗收,因此需要修改啟動(dòng)腳本
測(cè)試:
[root@mysql support-files]# sed -n "s#/usr/local/mysql#/application/mysql#pg" /application/mysql/bin/mysqld_safe
替換:
sed -i "s#/usr/local/mysql#/application/mysql#g" /application/mysql/bin/mysqld_safe
啟動(dòng)mysql
/application/mysql/bin/mysqld_safe &
MySQL常用優(yōu)化設(shè)置
設(shè)置密碼
/application/mysql/bin/mysqladmin -u root password '123456'
配置環(huán)境變量
echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile&&source /etc/profile&&tail -1 /etc/profile
加入到/etc/init.d/下
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i "s#/usr/local/mysql#/application/mysql#g" /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
測(cè)試啟動(dòng)
killall mysqld
mysqld: no process killed
[root@mysql sbin]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@mysql sbin]# lsof -i :3306
加入開(kāi)機(jī)啟動(dòng)
[root@mysql sbin]# chkconfig --add mysqld
[root@mysql sbin]# chkconfig mysqld --list
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
MySQL日志
ll /application/mysql/data/mysql.err
MySQL字符集
- 修改服務(wù)器級(jí)別字符集
打開(kāi)/etc/mysql/my.cnf,在[mysqld]后添加
character-set-server=utf8
- 更改連接字符集
打開(kāi)/etc/mysql/my.cnf,在[client]后添加
default-character-set=utf8