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

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

安裝Perl

yum install -y perl-Module-Install.noarch

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

[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: ******

切換到新建的用戶(hù)根目錄下(/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

更新目錄名稱(chēng)

[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

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

[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用戶(hù)的初始密碼

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

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

啟動(dòng)數(shù)據(jù)庫(kù)

[mall@localhost mysql]$ ./conf/startMysqld.sh 
cat: /home/mall/mysql/log/mysql.pid: No such file or directory
1、正在停止正在運(yùn)行的端口為3306的Mysql實(shí)例,PID:,請(qǐng)等待......
./conf/startMysqld.sh: line 18: [: -ne: unary operator expected
2、正在啟動(dòng)端口為3306的Mysql實(shí)例,請(qǐng)等待......
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、新啟動(dòng)的Mysql實(shí)例,PID:18374

測(cè)試數(shù)據(jù)庫(kù)

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

[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è)置遠(yuǎn)程登錄

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

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

修改Linux字符集##

步驟1:
修改i18n文件

vi /etc/sysconf/i18n

將默認(rèn)LANG修改為

LANG="zh_CN.UTF-8"

步驟2:
切換為mysql啟動(dòng)用戶(hù)(root、mall)

su root
注意:兩個(gè)用戶(hù)都需要設(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、正在停止正在運(yùn)行的端口為$port的Mysql實(shí)例,PID:$pid,請(qǐng)等待......"
if [ $pid -ne 0 ] 
  then
  kill $pid
  sleep 2
fi

echo "2、正在啟動(dòng)端口為$port的Mysql實(shí)例,請(qǐng)等待......"
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、檢查新啟動(dòng)的Mysql實(shí)例PID失敗,請(qǐng)手動(dòng)檢查進(jìn)程是否啟動(dòng)完成!"
else
  echo "3、新啟動(dòng)的Mysql實(shí)例,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ù)庫(kù)字符集##

alter database mall character set utf8mb4;

QA

1. 遠(yuǎn)程MySQL工具登錄不上,可能是防火墻未開(kāi)放MySQL端口訪(fǎng)問(wèn)權(quán)限

關(guān)閉防火墻

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

1.2、即時(shí)生效,重啟后失效:
開(kāi)啟:service iptables start
關(guān)閉:service iptables stop

2. MySQL安裝過(guò)程中遇到的問(wèn)題

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賬號(hào)就正常使用了。

資料

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容