linux上部署安装MySQL5.6.23

1.下载

  • 首先下载lrzsz:把事先在window上的mysql软件包上传到linux上
[root@grace ~]# yum -y install lrzsz
  • 进入到/usr/local目录
[root@grace ~]# cd /usr/local
[root@grace local]# rz
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
  100%  304464 KB 3420 KB/s 00:01:29       0 Errorssgz...
  • 输入rz命令弹出窗口选择windows下的mysql软件包
    rz
[root@grace local]# ll  #查看mysql是否已经上传成功
total 304512
drwxr-xr-x. 2 root root      4096 Sep 23  2011 bin
drwxr-xr-x. 2 root root      4096 Sep 23  2011 etc
drwxr-xr-x. 2 root root      4096 Sep 23  2011 games
drwxr-xr-x. 2 root root      4096 Sep 23  2011 include
drwxr-xr-x. 2 root root      4096 Sep 23  2011 lib
drwxr-xr-x. 2 root root      4096 Sep 23  2011 lib64
drwxr-xr-x. 2 root root      4096 Sep 23  2011 libexec
-rw-r--r--. 1 root root 311771412 Nov 30 16:18 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 2 root root      4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root      4096 Dec  1 17:35 share
drwxr-xr-x. 2 root root      4096 Sep 23  2011 src

2.检查电脑是否装过mysql

[root@grace local]# ps -ef|grep mysqld
root      2673  2602  0 23:29 pts/1    00:00:00 grep mysqld
[root@grace local]# rpm -qa |grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64

3.对上传好的mysql进行解压重命名

#解压
[root@grace local]# tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
[root@grace local]# ll
total 304816
drwxr-xr-x.  2 root root      4096 Sep 23  2011 bin
drwxr-xr-x.  2 root root      4096 Sep 23  2011 etc
drwxr-xr-x.  2 root root      4096 Sep 23  2011 games
drwxr-xr-x.  2 root root      4096 Sep 23  2011 include
drwxr-xr-x.  2 root root      4096 Sep 23  2011 lib
drwxr-xr-x.  2 root root      4096 Sep 23  2011 lib64
drwxr-xr-x.  2 root root      4096 Sep 23  2011 libexec
drwxr-xr-x. 13 root root      4096 Dec 11 11:01 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--.  1 root root 311771412 Nov 30 16:18 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x.  2 root root      4096 Sep 23  2011 sbin
drwxr-xr-x.  5 root root      4096 Dec  8 23:33 share
drwxr-xr-x.  2 root root      4096 Sep 23  2011 src
#重命名
[root@grace local]# mv mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz mysql
[root@grace local]# ll
total 304816
drwxr-xr-x.  2 root root      4096 Sep 23  2011 bin
drwxr-xr-x.  2 root root      4096 Sep 23  2011 etc
drwxr-xr-x.  2 root root      4096 Sep 23  2011 games
drwxr-xr-x.  2 root root      4096 Sep 23  2011 include
drwxr-xr-x.  2 root root      4096 Sep 23  2011 lib
drwxr-xr-x.  2 root root      4096 Sep 23  2011 lib64
drwxr-xr-x.  2 root root      4096 Sep 23  2011 libexec
drwxr-xr-x. 13 root root      4096 Dec 11 11:01 mysql
-rw-r--r--.  1 root root 311771412 Nov 30 16:18 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x.  2 root root      4096 Sep 23  2011 sbin
drwxr-xr-x.  5 root root      4096 Dec  8 23:33 share
drwxr-xr-x.  2 root root      4096 Sep 23  2011 src

4.添加mysql用户

  • 添加该用户管理mysql
#添加dba组,gid=101
[root@grace local]#  groupadd -g 101 dba 

#添加一个用户mysqladmin,uid=514 所在组=dba,root 指定家目录=/usr/local/mysql
[root@grace local]#  useradd -u 514 -g dba -G root -d 
/usr/local/mysql mysqladmin
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.

#查看mysqladmin用户信息
[root@grace local]#  id mysqladmin 
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)

5.copy 环境变量配置文件至mysqladmin用户的home目录中

为下面配置个人环境变量做准备
[root@grace local]#  cp /etc/skel/.* /usr/local/mysql
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.gnome2'
cp: omitting directory `/etc/skel/.mozilla'

6.创建/etc/my.cnf(640)

默认选择的路径为: /etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf-> –defaults-extra-file->~/my.cnf

[root@grace ~]# vi /etc/my.cnf

复制下面的内容到my.cnf目录

[client]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock

[mysqld]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock

skip-external-locking
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size= 32M
max_allowed_packet = 16M
myisam_sort_buffer_size=128M
tmp_table_size=32M

table_open_cache = 512
thread_cache_size = 8
wait_timeout = 86400
interactive_timeout = 86400
max_connections = 600


# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 32

#isolation level and default engine 
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED

server-id  = 1
basedir     = /usr/local/mysql
datadir     = /usr/local/mysql/data
pid-file     = /usr/local/mysql/data/hostname.pid

#open performance schema
log-warnings
sysdate-is-now

binlog_format = MIXED
log_bin_trust_function_creators=1
log-error  = /usr/local/mysql/data/hostname.err
log-bin=/usr/local/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file  = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err

#for replication slave
#log-slave-updates 
#sync_binlog = 1

binlog_format = MIXED
log_bin_trust_function_creators=1
log-error  = /usr/local/mysql/data/hostname.err
log-bin=/usr/local/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file  = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err

#for replication slave
#log-slave-updates 
#sync_binlog = 1

#for innodb options 
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ibdata1:500M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/arch
innodb_log_files_in_group = 2
innodb_log_file_size = 200M

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 50M
innodb_log_buffer_size = 16M

innodb_lock_wait_timeout = 100
#innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_locks_unsafe_for_binlog=1

#innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads=4
innodb-write-io-threads=4
innodb-io-capacity=200
#purge threads change default(0) to 1 for purge
innodb_purge_threads=1
innodb_use_native_aio=on

#case-sensitive file names and separate tablespace
innodb_file_per_table = 1
lower_case_table_names=1

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[mysqlhotcopy]
interactive-timeout

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

第27行的innodb_buffer_pool_size = 2048M根据实际的剩余内存分配

7.权限设置

[root@grace local]# chown  mysqladmin:dba /etc/my.cnf
[root@grace local]# chmod  640 /etc/my.cnf 
[root@grace local]# ll /etc/my.cnf 
-rw-r-----. 1 mysqladmin dba 2218 Dec  8 23:56 /etc/my.cnf

[root@grace local]# chown -R mysqladmin:dba /usr/local/mysql
[root@grace local]#  chmod -R 755 /usr/local/mysql 
[root@grace local]#  su - mysqladmin 
[mysqladmin@hadoop003 ~]$  pwd
/usr/local/mysql
[mysqladmin@grace ~]$  mkdir arch

8.下载libaio包

  1. 切换root用户
[mysqladmin@grace ~]$ su - root
Password: 
  1. 查看版本
[root@grace ~]# cat /proc/version
Linux version 2.6.32-431.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 22 03:15:09 UTC 2013
[root@grace ~]#  rpm -qa |grep gcc
libgcc-4.4.7-4.el6.x86_64
  1. 安装libaio
[root@grace ~]#  yum -y install libaio
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.nju.edu.cn
Setting up Install Process
Package libaio-0.3.107-10.el6.x86_64 already installed and latest version
Nothing to do

9. 进行安装

1.切换至mysqladmin

[root@grace ~]# su - mysqladmin

2.安装

[mysqladmin@grace ~]$ scripts/mysql_install_db  --user=mysqladmin --basedir=/usr/local/mysql 
--datadir=/usr/local/mysql/data

Installing MySQL system tables...2017-12-09 00:03:05 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-12-09 00:03:05 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

Filling help tables...2017-12-09 00:03:48 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-12-09 00:03:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
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:

  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h hadoop003 password 'new-password'

Alternatively you can run:

  /usr/local/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 . ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

10. 设置开机自启动

1.切换至root

[mysqladmin@grace ~]$ su - root
[root@grace ~]# cd /usr/local/mysql

2.将服务文件拷贝到init.d下,并重命名为mysql

[root@grace mysql]#  cp support-files/mysql.server /etc/rc.d/init.d/mysql

3.赋予可执行权限

[root@grace mysql]# chmod +x /etc/rc.d/init.d/mysql

4.删除服务

[root@grace mysql]# chkconfig --del mysql

5.添加服务

[root@grace mysql]# chkconfig --add mysql
[root@grace mysql]# chkconfig --level 345 mysql on

11. 开启mysql,并查看进程

1.切换root

[root@grace mysql]# su - mysqladmin
[mysqladmin@grace ~]$ pwd

2.删除my.cnf

[mysqladmin@grace ~]$ rm -rf my.cnf

3.后台启动mysql

[mysqladmin@grace ~]$ bin/mysqld_safe &
[1] 4850
[mysqladmin@grace ~]$ 171211 12:24:42 mysqld_safe Logging to '/usr/local/mysql/data/hostname.err'.
171211 12:24:42  mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
(按回车键完成启动)

4.查看进程

[root@grace etc]# su - mysqladmin
[mysqladmin@grace ~]$  ps -ef|grep mysqld
514       4850  4825  0 12:24 pts/2    00:00:00 /bin/sh bin/mysqld_safe
514       5493  4850  8 12:24 pts/2    00:00:04 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/hostname.err --pid-file=/usr/local/mysql/data/hostname.pid --socket=/usr/local
/mysql/data/mysql.sock --port=3306
514       5547  5521  0 12:25 pts/2    00:00:00 grep mysqld

[mysqladmin@grace~]$  netstat -tulnp | grep mysql
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 :::3306                     :::*                        LISTEN      5493/mysqld  

5.在root用户下查看服务

[mysqladmin@grace ~]$ su - root
Password: 
[root@grace ~]#  service mysql status
MySQL running (3687)[  OK  ]

6.登录mysql

[mysqladmin@grace ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值