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