02 Mysql5.6 数据库安装

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

安装Perl

yum install -y perl-Module-Install.noarch

使用root创建用户组、用户

[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

执行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'

注意:用于生产环境的初始密码必须设置足够复杂,这里仅用于测试。

启动数据库

[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

测试数据库

登录数据库

[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)

设置远程登录

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

注意:这两条语句是需要先登录数据库才能执行,[123456]密码需要替换为root的密码。

修改Linux字符集##

步骤1:
修改i18n文件

vi /etc/sysconf/i18n

将默认LANG修改为

LANG="zh_CN.UTF-8"

步骤2:
切换为mysql启动用户(root、mall)

su root
注意:两个用户都需要设置

编辑.bash_profile文件

vi ~/.bash_profile

在文件的最后增加两行

export LANG=zh_CN.UTF-8
export LANG

退出编辑,执行

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

修改数据库字符集##

alter database mall character set utf8mb4;

QA

1. 远程MySQL工具登录不上,可能是防火墙未开放MySQL端口访问权限

关闭防火墙

1.1、重启后永久性生效:
开启:chkconfig iptables on
关闭:chkconfig iptables off

1.2、即时生效,重启后失效:
开启:service iptables start
关闭:service iptables stop

2. MySQL安装过程中遇到的问题

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

3. 执行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');
刷新权限
mysql> flush privileges;
root账号就正常使用了。

资料

MySql my.cnf
MySQL如何避免使用Linux的swap分区而提升读写性能
SWAP的罪与罚
MySQL 内存占用过高分析
MySQL命令行--导入导出数据库
MySQL字符集utf8mb4

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,277评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,777评论 1 298
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,946评论 0 245
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,271评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,636评论 3 288
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,767评论 1 221
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,989评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,733评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,457评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,674评论 2 249
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,155评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,518评论 3 258
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,160评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,114评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,898评论 0 198
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,822评论 2 280
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,705评论 2 273

推荐阅读更多精彩内容