02 Mysql5.6 數(shù)據(jù)庫安裝

CentOS7 通過YUM安裝MySQL5.7
https://www.cnblogs.com/jorzy/p/8455519.html

安裝Perl

yum install -y perl-Module-Install.noarch

使用root創(chuàng)建用戶組、用戶

[root@localhost ~]# groupadd mall
[root@localhost ~]# useradd mall -g mall
[root@localhost ~]# su mall
[root@localhost 1.6.0_45]# passwd mall
Changing password for user mall.
New password: ******

切換到新建的用戶根目錄下(/home/mall/)
[root@localhost ~]# cd ~

下載Mysql安裝包

wget mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz

解壓縮安裝包

[mall@localhost ~]$ tar vxf mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz 
.....
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/insert_select-binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_2.inc
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/ctype_ucs_binlog.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/binlog_mysqlbinlog_row.inc
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/implicit.test
mysql-5.6.22-linux-glibc2.5-x86_64/mysql-test/extra/binlog_tests/blackhole.test

更新目錄名稱

[mall@localhost ~]$ mv mysql-5.6.22-linux-glibc2.5-x86_64 mysql
[mall@localhost ~]$ ll
total 304364
drwxrwxr-x. 13 mall mall      4096 Sep 18 20:06 mysql

上傳配置文件九秀、啟動命令到conf目錄下(注意,這里使用的是root用戶)

[root@localhost mysql]$ mkdir conf
[root@localhost mysql]# pwd
/home/mall/mysql
[root@localhost mysql]# chown -R mall:mall conf
[root@localhost mysql]# cd conf/
[root@localhost conf]# ll
total 8
-rw-r--r--. 1 mall mall 2943 Sep 18 20:09 my.cnf
-rw-r--r--. 1 mall mall 1017 Sep 18 20:09 startMysqld.sh
[root@localhost conf]# chmod +x startMysqld.sh

執(zhí)行Mysql初始化腳本

[mall@localhost mysql]$ ./scripts/mysql_install_db --user=mall --basedir=/home/mall/mysql/ --datadir=/home/mall/mysql/data/
Installing MySQL system tables...2016-09-18 20:13:06 0 [Warning] TIMESTAMP with implicit DEFAULT     value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-09-18 20:13:07 18308 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2016-09-18 20:13:07 18308 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
........
2016-09-18 20:13:11 18330 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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:

/home/mall/mysql//bin/mysqladmin -u root password 'new-password'
/home/mall/mysql//bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
........

初始化Mysql root用戶的初始密碼

/home/mall/mysql/bin/mysqladmin -u root -h 127.0.0.1 -P 3306 password '123456'

注意:用于生產(chǎn)環(huán)境的初始密碼必須設(shè)置足夠復(fù)雜,這里僅用于測試。

啟動數(shù)據(jù)庫

[mall@localhost mysql]$ ./conf/startMysqld.sh 
cat: /home/mall/mysql/log/mysql.pid: No such file or directory
1态兴、正在停止正在運行的端口為3306的Mysql實例,PID:,請等待......
./conf/startMysqld.sh: line 18: [: -ne: unary operator expected
2峭拘、正在啟動端口為3306的Mysql實例匹摇,請等待......
2016-09-18 20:17:16 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future     release.
2016-09-18 20:17:16 0 [Warning] Ignoring user change to 'mall' because the user was set to 'umeng' earlier on the command line

2016-09-18 20:17:16 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-09-18 20:17:16 18374 [Warning] One can only use the --user switch if running as root

3咬扇、新啟動的Mysql實例,PID:18374

測試數(shù)據(jù)庫

登錄數(shù)據(jù)庫

[mall@localhost mysql]$ /home/mall/mysql/bin/mysql -u root -h 127.0.0.1 -P 3306 -prootpwd
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.22-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. 
Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.04 sec)

設(shè)置遠程登錄

GRANT ALL PRIVILEGES ON *.* TO root@'%' identified by '123456';
flush privileges;

注意:這兩條語句是需要先登錄數(shù)據(jù)庫才能執(zhí)行廊勃,[123456]密碼需要替換為root的密碼懈贺。

修改Linux字符集##

步驟1:
修改i18n文件

vi /etc/sysconf/i18n

將默認LANG修改為

LANG="zh_CN.UTF-8"

步驟2:
切換為mysql啟動用戶(root、mall)

su root
注意:兩個用戶都需要設(shè)置

編輯.bash_profile文件

vi ~/.bash_profile

在文件的最后增加兩行

export LANG=zh_CN.UTF-8
export LANG

退出編輯坡垫,執(zhí)行

source ~/.bash_profile

startMysqld.sh腳本源碼

#! /bin/bash
port=3306
user=mall
basedir=${HOME}/mysql

mkdir -p ${basedir}/{tmp,data,log}

while getopts 'p:u:' opt
do
  case $opt in
    p)port=$OPTARG;;
    u)user=$OPTARG;;
  esac
done

pid=`cat ${basedir}/log/mysql.pid`
echo "1隅居、正在停止正在運行的端口為$port的Mysql實例,PID:$pid,請等待......"
if [ $pid -ne 0 ] 
  then
  kill $pid
  sleep 2
fi

echo "2葛虐、正在啟動端口為$port的Mysql實例胎源,請等待......"
echo 0 > ${basedir}/log/mysql.pid
${basedir}/bin/mysqld --defaults-file=${basedir}/conf/my.cnf --basedir=${basedir} \
--datadir=${basedir}/data --plugin-dir=${basedir}/lib/plugin --log-error=${basedir}/log/mysqld.err \
--open-files-limit=102400 --pid-file=${basedir}/log/mysql.pid --socket=${basedir}/tmp/mysql.sock \
--user=${user} --port=${port}&

sleep 5
pid=`cat ${basedir}/log/mysql.pid`
if [ $pid -eq 0 ] 
  then
  echo "3、檢查新啟動的Mysql實例PID失敗屿脐,請手動檢查進程是否啟動完成涕蚤!"
else
  echo "3、新啟動的Mysql實例的诵,PID:$pid"
fi

my.cnf腳本源碼

[client]
port = 3307
socket = 
socket = /home/mall/mysql/tmp/mysql.sock
default-character-set = utf8

[mysqld]
character-set-server = utf8
port = 3307
socket = /home/mall/mysql/tmp/mysql.sock
socket = 
user    = umeng
skip-external-locking
datadir = /home/mall/mysql/data/
log-error = /home/mall/mysql/log/mysqld.err
pid-file = /home/mall/mysql/log/mysql.pid
#init_connect='set autocommit=0' 
#init_connect='set names utf8'
#read-only

key_buffer_size = 64M
myisam_sort_buffer_size = 2048M
max_allowed_packet = 16M
table_open_cache = 4096
sort_buffer_size = 3M
join_buffer_size = 3M
read_buffer_size = 3M
read_rnd_buffer_size = 5M
bulk_insert_buffer_size = 64M
query_cache_size = 64M
query_cache_type = 2
query_cache_limit=512k
query_cache_min_res_unit = 2k
tmp_table_size=32M
max_tmp_tables=128
max_heap_table_size = 256M

open_files_limit=102400
thread_concurrency = 16
max_connections=3000
max_connect_errors=3000
back_log = 600
#table_cache = 4096
thread_cache_size = 300
thread_stack = 192K
#transaction_isolation = READ-COMMITTED

skip-name-resolve

####log variables
server-id = 13243
binlog_format=mixed
#log-slave-updates
log-bin = /home/mall/mysql/log/mysql-bin
relay_log = /home/mall/mysql/log/relay-bin
max_binlog_size = 500M
binlog_cache_size = 1M
max_binlog_cache_size = 4096M
#binlog-ignore-db = mysql
replicate-ignore-db = mysql
expire-logs-days = 8
sync_binlog=20
binlog-do-db=ucgc_dzms
binlog-ignore-db=mysql
log-slave-updates

slow_query_log=1
slow_query_log_file = /home/mall/mysql/log/slowquery.log
long_query_time=1
general_log=off
general_log_file = /home/mall/mysql/log/general.log
#relay_log_purge=OFF

# Point the following paths to different dedicated disks
#tmpdir         = /tmp/
#log-update     = /path-to-dedicated-directory/hostname

#auto_increment_increment=1
#auto_increment_offset=1

####innodb variables
#skip-innodb
#ignore_builtin_innodb
innodb_data_home_dir = /home/mall/mysql/data/
innodb_data_file_path = ibdata1:12M;ibdata2:100M:autoextend
innodb_autoextend_increment = 64
innodb_log_group_home_dir = /home/mall/mysql/data/
#innodb_log_arch_dir = /home/mall/mysql/log/
innodb_buffer_pool_size = 180M
innodb_additional_mem_pool_size = 32M
innodb_log_file_size = 360M
innodb_log_buffer_size = 8M
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 2
#innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_thread_sleep_delay = 100
default-storage-engine=innodb
innodb_max_dirty_pages_pct = 50
#innodb_lock_wait_timeout = 60
#innodb_file_per_table = 0
#innodb_support_xa=1
#innodb_io_capacity=200
innodb_flush_method=O_DSYNC
innodb_force_recovery=1

#interactive_timeout = 600
#wait_timeout = 900

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 5M
write_buffer = 5M

[mysqlhotcopy]
interactive-timeout

修改數(shù)據(jù)庫字符集##

alter database mall character set utf8mb4;

QA

1. 遠程MySQL工具登錄不上万栅,可能是防火墻未開放MySQL端口訪問權(quán)限

關(guān)閉防火墻

1.1、重啟后永久性生效:
開啟:chkconfig iptables on
關(guān)閉:chkconfig iptables off

1.2西疤、即時生效烦粒,重啟后失效:
開啟:service iptables start
關(guān)閉:service iptables stop

2. MySQL安裝過程中遇到的問題

http://blog.csdn.net/yaoqinglin/article/details/45269247

3. 執(zhí)行SQL文件

source /root/mysql/init_sql/init.sql

4. 缺少libaio.so.1包

[root@mall_api lib64]# yum list | grep 'libaio-dev'
libaio-devel.i686                          0.3.107-10.el6              base     
libaio-devel.x86_64                        0.3.107-10.el6              base     
[root@mall_api lib64]# 
[root@mall_api lib64]# yum install libaio-devel
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
 * base: mirror.amsiohosting.net
 * extras: nl.mirror.babylon.network
 * updates: mirror.amsiohosting.net
Resolving Dependencies
--> Running transaction check
---> Package libaio-devel.x86_64 0:0.3.107-10.el6 will be installed
--> Processing Dependency: libaio = 0.3.107-10.el6 for package: libaio-devel-0.3.107-10.el6.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.107-10.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

5. 修改root密碼

mysql> set password =password('123456');
刷新權(quán)限
mysql> flush privileges;
root賬號就正常使用了。

資料

MySql my.cnf
MySQL如何避免使用Linux的swap分區(qū)而提升讀寫性能
SWAP的罪與罰
MySQL 內(nèi)存占用過高分析
MySQL命令行--導(dǎo)入導(dǎo)出數(shù)據(jù)庫
MySQL字符集utf8mb4

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末代赁,一起剝皮案震驚了整個濱河市扰她,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌芭碍,老刑警劉巖徒役,帶你破解...
    沈念sama閱讀 212,718評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異窖壕,居然都是意外死亡忧勿,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,683評論 3 385
  • 文/潘曉璐 我一進店門瞻讽,熙熙樓的掌柜王于貴愁眉苦臉地迎上來鸳吸,“玉大人,你說我怎么就攤上這事速勇∩卫” “怎么了?”我有些...
    開封第一講書人閱讀 158,207評論 0 348
  • 文/不壞的土叔 我叫張陵快集,是天一觀的道長贡羔。 經(jīng)常有香客問我,道長个初,這世上最難降的妖魔是什么乖寒? 我笑而不...
    開封第一講書人閱讀 56,755評論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮院溺,結(jié)果婚禮上楣嘁,老公的妹妹穿的比我還像新娘。我一直安慰自己珍逸,他們只是感情好逐虚,可當我...
    茶點故事閱讀 65,862評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著谆膳,像睡著了一般叭爱。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上漱病,一...
    開封第一講書人閱讀 50,050評論 1 291
  • 那天买雾,我揣著相機與錄音,去河邊找鬼杨帽。 笑死漓穿,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的注盈。 我是一名探鬼主播晃危,決...
    沈念sama閱讀 39,136評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼老客!你這毒婦竟也來了僚饭?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,882評論 0 268
  • 序言:老撾萬榮一對情侶失蹤胧砰,失蹤者是張志新(化名)和其女友劉穎浪慌,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體朴则,經(jīng)...
    沈念sama閱讀 44,330評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡权纤,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,651評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了乌妒。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片汹想。...
    茶點故事閱讀 38,789評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖撤蚊,靈堂內(nèi)的尸體忽然破棺而出古掏,到底是詐尸還是另有隱情,我是刑警寧澤侦啸,帶...
    沈念sama閱讀 34,477評論 4 333
  • 正文 年R本政府宣布槽唾,位于F島的核電站丧枪,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏庞萍。R本人自食惡果不足惜拧烦,卻給世界環(huán)境...
    茶點故事閱讀 40,135評論 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望钝计。 院中可真熱鬧恋博,春花似錦、人聲如沸私恬。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,864評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽本鸣。三九已至疫衩,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間荣德,已是汗流浹背隧土。 一陣腳步聲響...
    開封第一講書人閱讀 32,099評論 1 267
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留命爬,地道東北人曹傀。 一個月前我還...
    沈念sama閱讀 46,598評論 2 362
  • 正文 我出身青樓,卻偏偏與公主長得像饲宛,于是被迫代替她去往敵國和親皆愉。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 43,697評論 2 351

推薦閱讀更多精彩內(nèi)容