在Linux下装二进制MySQL

                                          MySQL (mysql)二进制部署

1.scp : A机器(linux)将文件或文件夹传到B机器(linux)
eg:
[root@xkhadoop local]# scp mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz [email protected]:/usr/local/
The authenticity of host '192.168.40.130 (192.168.40.130)' can't be established.
RSA key fingerprint is de:bc:d1:49:56:38:a8:bf:f6:41:6c:df:93:38:d4:ad.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.40.130' (RSA) to the list of known hosts.

[email protected]'s password: 
mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz                                                         100%  297MB  13.5MB/s   00:22


2.路径: 绝对路径 相对路径
绝对路径:指的是一个完整的路径
eg:
[root@xkhadoop ~]# cd /usr/local/mysql
[root@xkhadoop mysql]# 
相对路径:指的是基于目前路径下的路径
eg:
[root@xkhadoop ~]# cd /usr/local/mysql
[root@xkhadoop mysql]# 

3.软连接:
ln -s 实际路径 软连接路径(路径全是绝对路径)
eg:
[root@xkhadoop001 local]# ln -s /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64 /usr/local/mysql
[root@xkhadoop001 local]# ll
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
lrwxrwxrwx.  1 root root        45 Nov  4 16:24 mysql -> /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64
drwxr-xr-x. 13 root root      4096 Nov  4 16:15 mysql-5.6.23-linux-glibc2.5-x86_64
-rw-r--r--.  1 root root 311771412 Nov  4 15:55 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 Oct 27 03:03 share
drwxr-xr-x.  2 root root      4096 Sep 23  2011 src

二进制MySQL安装顺序:

1.先把文件考进机器(rz)或者把另一台机器里面的包通过scp传输到新机器里面:
[root@xkhadoop local]# scp mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz [email protected]:/usr/local/
The authenticity of host '192.168.40.130 (192.168.40.130)' can't be established.
RSA key fingerprint is de:bc:d1:49:56:38:a8:bf:f6:41:6c:df:93:38:d4:ad.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.40.130' (RSA) to the list of known hosts.

[email protected]'s password: 
mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz  

2.解压包:tar -xzvf
eg:
tar -xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

[root@xkhadoop001 local]# ll
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
drwxr-xr-x. 13 root root      4096 Nov  4 16:15 mysql-5.6.23-linux-glibc2.5-x86_64
-rw-r--r--.  1 root root 311771412 Nov  4 15:55 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 Oct 27 03:03 share
drwxr-xr-x.  2 root root      4096 Sep 23  2011 src

3.重命名或者软连接
软链接:
[root@xkhadoop001 local]# ln -s /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64 /usr/local/mysql
[root@xkhadoop001 local]# ll
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
lrwxrwxrwx.  1 root root        45 Nov  4 16:24 mysql -> /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64
drwxr-xr-x. 13 root root      4096 Nov  4 16:15 mysql-5.6.23-linux-glibc2.5-x86_64
-rw-r--r--.  1 root root 311771412 Nov  4 15:55 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 Oct 27 03:03 share
drwxr-xr-x.  2 root root      4096 Sep 23  2011 src

重命名:
[root@xkhadoop001 local]# mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql

4.创建用户组和用户:

 [root@xkhadoop001 mysql]# groupadd -g 101 dba
[root@xkhadoop001 mysql]# 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.
[root@xkhadoop001 mysql]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
[root@xkhadoop001 mysql]# passwd mysqladmin
Changing password for user mysqladmin.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@xkhadoop001 mysql]#  


5.卸载机器里面的mysql的rpm包:
[root@xkhadoop001 mysql]# rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@xkhadoop001 mysql]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
[root@xkhadoop001 mysql]# rpm -qa|grep mysql


6.copy 环境变量配置文件至mysqladmin用户的home目录中,为了以下步骤配置个人环境变量
[root@xkhadoop001 mysql]# 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'

7.vi my.cnf配置文件

[root@xkhadoop001 mysql]# vi /etc/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

#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 = 1024M
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

8.配置用户组和用户的权限:

[root@xkhadoop001 mysql]# chown  mysqladmin:dba /etc/my.cnf 
[root@xkhadoop001 mysql]# chmod  640 /etc/my.cnf


(1).重命名:
[root@xkhadoop001 mysql]# chown  mysqladmin:dba /etc/my.cnf 
[root@xkhadoop001 mysql]# chmod  640 /etc/my.cnf
[root@xkhadoop001 mysql]# chown -R mysqladmin:dba /usr/local/mysql
[root@xkhadoop001 mysql]# chmod -R 755 /usr/local/mysql
[root@xkhadoop001 local]# ll
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
lrwxrwxrwx.  1 mysqladmin dba         45 Nov  4 16:24 mysql
drwxr-xr-x. 13 root       root      4096 Nov  4 16:36 mysql-5.6.23-linux-glibc2.5-x86_64
-rw-r--r--.  1 root       root 311771412 Nov  4 15:55 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 Oct 27 03:03 share
drwxr-xr-x.  2 root       root      4096 Sep 23  2011 src

(2).软连接:

[root@xkhadoop001 mysql]# chown  mysqladmin:dba /etc/my.cnf 
[root@xkhadoop001 mysql]# chmod  640 /etc/my.cnf
[root@xkhadoop001 mysql]# chown -R mysqladmin:dba /usr/local/mysql
[root@xkhadoop001 mysql]# chmod -R 755 /usr/local/mysql
[root@xkhadoop001 local]# ll
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
lrwxrwxrwx.  1 mysqladmin dba         45 Nov  4 16:24 mysql -> /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64
drwxr-xr-x. 13 root       root      4096 Nov  4 16:36 mysql-5.6.23-linux-glibc2.5-x86_64
-rw-r--r--.  1 root       root 311771412 Nov  4 15:55 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 Oct 27 03:03 share
drwxr-xr-x.  2 root       root      4096 Sep 23  2011 src

[root@xkhadoop001 local]# chown -R mysqladmin:dba /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64
[root@xkhadoop001 local]# chmod -R 755 /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64
[root@xkhadoop001 local]# chown -R mysqladmin:dba /usr/local/mysql/*
[root@xkhadoop001 local]# chmod -R 755 /usr/local/mysql/*
[root@xkhadoop001 local]# chown -R mysqladmin:dba /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64/*
[root@xkhadoop001 local]# chmod -R 755 /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64/*
[root@xkhadoop001 local]# ll
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
lrwxrwxrwx.  1 mysqladmin dba         45 Nov  4 16:24 mysql -> /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64
drwxr-xr-x. 13 mysqladmin dba       4096 Nov  4 16:36 mysql-5.6.23-linux-glibc2.5-x86_64
-rw-r--r--.  1 root       root 311771412 Nov  4 15:55 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 Oct 27 03:03 share
drwxr-xr-x.  2 root       root      4096 Sep 23  2011 src


9.MySQL初始化安装:

[mysqladmin@xkhadoop001 ~]$ mkdir arch
[mysqladmin@xkhadoop001 ~]$ scripts/mysql_install_db  --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
WARNING: The host 'xkhadoop001' could not be looked up with /usr/local/mysql/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !

Installing MySQL system tables...2018-11-04 16:59:12 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2018-11-04 16:59:12 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...2018-11-04 16:59:49 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2018-11-04 16:59:49 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 xkhadoop001 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

WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

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

[mysqladmin@xkhadoop001 ~]$ 

10.部署开机自启动:

[root@xkhadoop001 ~]# cd /usr/local/mysql
[root@xkhadoop001 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql 
#将服务文件拷贝到init.d下,并重命名为mysql
[root@xkhadoop001 mysql]# chmod +x /etc/rc.d/init.d/mysql
#赋予可执行权限
[root@xkhadoop001 mysql]# chkconfig --del mysql
#删除服务
[root@xkhadoop001 mysql]# chkconfig --add mysql
#添加服务
[root@xkhadoop001 mysql]# chkconfig --level 345 mysql on
[root@xkhadoop001 mysql]# su - mysqladmin
[mysqladmin@xkhadoop001 ~]$ bin/mysqld_safe & 
#后台启动

#有可能出现错误
    #先卸载
    #[root@xkhadoop001 lib]# rpm --nodeps -e mysql-libs-5.1.71-1.el6.x86_64
    #改权限
    #[root@xkhadoop001 mysql]# chmod -R 757 /var/log 

11.启动MySQL:
[mysqladmin@xkhadoop001 ~]$ bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
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.

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

mysql> 

猜你喜欢

转载自blog.csdn.net/qq_41301707/article/details/83717635