一、离线安装包 文件准备

  这里以mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz为例,记一次MySQL 5.6.x 的生产环境离线部署过程。使用SecureCRT连接生产部署的机器,这里注意使用root用户进行操作。

  mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz文件,已放到网盘(为什么不放到仓库的原因:****,习惯了 ),

    链接:https://pan.baidu.com/s/1aOC4jUiVa5KcLS7dQwyCbA          提取码:kvuo

  1、检查是否安装过mysqld

[root@slave054 local]# ps -ef|grep mysqld
root : pts/ :: grep --color=auto mysqld

[root@slave054 local]# rpm -qa |grep -i mysql

[root@slave054 local]# ps -ef|grep mysqld
root : pts/ :: grep --color=auto mysqld

  2、切换到/usr/local目录下

[root@slave054 ~]#  cd /usr/local
[root@slave054 local]# pwd
/usr/local
[root@slave054 local]#

 

  3、使用rz 上传mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz压缩文件

[root@slave054 local]# ll
total
drwxr-xr-x. root root Apr bin
drwxr-xr-x. root root Apr etc
drwxr-xr-x. root root Apr games
drwxr-xr-x. root root Apr include
drwxr-xr-x. root root Apr lib
drwxr-xr-x. root root Apr lib64
drwxr-xr-x. root root Apr libexec
drwxr-xr-x. root root Apr sbin
drwxr-xr-x. root root Nov : share
drwxr-xr-x. root root Apr src
[root@slave054 local]# rz
rz waiting to receive.
zmodem trl+C ȡ % KB KB/s :: Errorssc2.-x86_64.tar.gz... [root@slave054 local]#

[root@slave054 local]# ll
total
drwxr-xr-x. root root Apr bin
drwxr-xr-x. root root Apr etc
drwxr-xr-x. root root Apr games
drwxr-xr-x. root root Apr include
drwxr-xr-x. root root Apr lib
drwxr-xr-x. root root Apr lib64
drwxr-xr-x. root root Apr libexec
-rw-r--r--. root root Nov : mysql-5.6.-linux-glibc2.-x86_64.tar.gz
drwxr-xr-x. root root Apr sbin
drwxr-xr-x. root root Nov : share
drwxr-xr-x. root root Apr src
[root@slave054 local]#

  

二、解压文件并建立软连接

  1、解压mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

[root@slave054 local]#  tar xzvf mysql-5.6.-linux-glibc2.-x86_64.tar.gz

  2、建立软连接

[root@slave054 local]# ln -s  mysql-5.6.-linux-glibc2.-x86_64 mysql

[root@slave054 local]# ll
total
drwxr-xr-x. root root Apr bin
drwxr-xr-x. root root Apr etc
drwxr-xr-x. root root Apr games
drwxr-xr-x. root root Apr include
drwxr-xr-x. root root Apr lib
drwxr-xr-x. root root Apr lib64
drwxr-xr-x. root root Apr libexec
lrwxrwxrwx. root root Nov : mysql -> mysql-5.6.-linux-glibc2.-x86_64
drwxr-xr-x. root root Nov : mysql-5.6.-linux-glibc2.-x86_64
-rw-r--r--. root root Nov : mysql-5.6.-linux-glibc2.-x86_64.tar.gz
drwxr-xr-x. root root Apr sbin
drwxr-xr-x. root root Nov : share
drwxr-xr-x. root root Apr src
[root@slave054 local]#

三、用户和用户组

  1、添加dba用户组

[root@slave054 local]# groupadd -g  dba

  2、新建mysqladmin用户

[root@slave054 local]# useradd -u  -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@slave054 local]# id mysqladmin
uid=(mysqladmin) gid=(dba) groups=(dba),(root) [root@slave054 local]# passwd mysqladmin
Changing password for user mysqladmin.
New password:
BAD PASSWORD: The password is shorter than characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@slave054 local]#

  如果mysqladmin 已经存在,则执行如下命令:

usermod -u  -g dba -G root -d /usr/local/mysql mysqladmin

  3、复制环境变量配置文件至mysqladmin用户的home目录

[root@slave054 local]# cp /etc/skel/.* /usr/local/mysql
cp: omitting directory ‘/etc/skel/.’
cp: omitting directory ‘/etc/skel/..’
cp: omitting directory ‘/etc/skel/.mozilla’
[root@slave054 local]#

  4、my.cnf文件配置

[root@slave054 local]# cd /etc/
[root@slave054 etc]# vi my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid #
# include all files from the config directory
#
!includedir /etc/my.cnf.d ~
~
~
~
"my.cnf" 19L, 570C

my.cnf默认配置

  将以下的内容,替换掉原来默认的my.cnf默认配置内容,注意vim要进入-- INSERT --模式才能开始粘贴,否则粘贴的内容会不完全

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid #
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[client]
port =
socket = /usr/local/mysql/data/mysql.sock [mysqld]
port =
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 =
thread_cache_size =
wait_timeout =
interactive_timeout =
max_connections = # Try number of CPU's*2 for thread_concurrency
thread_concurrency = #isolation level and default engine
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED server-id =
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=
log-error = /usr/local/mysql/data/hostname.err
log-bin=/usr/local/mysql/arch/mysql-bin
#other logs
#general_log =
#general_log_file = /usr/local/mysql/data/general_log.err
#slow_query_log=
#slow_query_log_file=/usr/local/mysql/data/slow_log.err #for replication slave
#log-slave-updates
#sync_binlog = #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 =
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 =
#innodb_thread_concurrency =
innodb_flush_log_at_trx_commit =
innodb_locks_unsafe_for_binlog= #innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads=
innodb-write-io-threads=
innodb-io-capacity=
#purge threads change default() to for purge
innodb_purge_threads=
innodb_use_native_aio=on #case-sensitive file names and separate tablespace
innodb_file_per_table =
lower_case_table_names= [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

替换配置后的效果

  如果需要进行mysql调优,只需要调整*_buffer_size的参数即可,切记根据实际需求修改。

  注意:

  defualt start: /etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf-> --defaults-extra-file->~/my.cnf

  5、权限与文件所有者

[root@slave054 etc]# cd -
/usr/local [root@slave054 local]# chown mysqladmin:dba /etc/my.cnf [root@slave054 local]# chmod /etc/my.cnf [root@slave054 local]# ll /etc/my.cnf
-rw-r-----. mysqladmin dba Nov : /etc/my.cnf [root@slave054 local]# ll |grep mysql
lrwxrwxrwx. root root Nov : mysql -> mysql-5.6.-linux-glibc2.-x86_64
drwxr-xr-x. root root Nov : mysql-5.6.-linux-glibc2.-x86_64
-rw-r--r--. root root Nov : mysql-5.6.-linux-glibc2.-x86_64.tar.gz [root@slave054 local]# chown -R mysqladmin:dba /usr/local/mysql [root@slave054 local]# ll |grep mysql
lrwxrwxrwx. mysqladmin dba Nov : mysql -> mysql-5.6.-linux-glibc2.-x86_64
drwxr-xr-x. root root Nov : mysql-5.6.-linux-glibc2.-x86_64
-rw-r--r--. root root Nov : mysql-5.6.-linux-glibc2.-x86_64.tar.gz [root@slave054 local]# chown -R mysqladmin:dba /usr/local/mysql-5.6.-linux-glibc2.-x86_64 [root@slave054 local]# ll |grep mysql
lrwxrwxrwx. mysqladmin dba Nov : mysql -> mysql-5.6.-linux-glibc2.-x86_64
drwxr-xr-x. mysqladmin dba Nov : mysql-5.6.-linux-glibc2.-x86_64
-rw-r--r--. root root Nov : mysql-5.6.-linux-glibc2.-x86_64.tar.gz [root@slave054 local]# chmod -R /usr/local/mysql [root@slave054 local]# chmod -R /usr/local/mysql-5.6.-linux-glibc2.-x86_64 [root@slave054 local]# ll |grep mysql
lrwxrwxrwx. mysqladmin dba Nov : mysql -> mysql-5.6.-linux-glibc2.-x86_64
drwxr-xr-x. mysqladmin dba Nov : mysql-5.6.-linux-glibc2.-x86_64
-rw-r--r--. root root Nov : mysql-5.6.-linux-glibc2.-x86_64.tar.gz
[root@slave054 local]#

四、mysqladmin用户配置mysql

  1、登录mysqladmin用户

[root@slave054 local]# su - mysqladmin
[mysqladmin@slave054 ~]$ pwd
/usr/local/mysql
[mysqladmin@slave054 ~]$ ll
total
drwxr-xr-x. mysqladmin dba Nov : bin
-rwxr-xr-x. mysqladmin dba Jan COPYING
drwxr-xr-x. mysqladmin dba Nov : data
drwxr-xr-x. mysqladmin dba Nov : docs
drwxr-xr-x. mysqladmin dba Nov : include
-rwxr-xr-x. mysqladmin dba Jan INSTALL-BINARY
drwxr-xr-x. mysqladmin dba Nov : lib
drwxr-xr-x. mysqladmin dba Nov : man
drwxr-xr-x. mysqladmin dba Nov : mysql-test
-rwxr-xr-x. mysqladmin dba Jan README
drwxr-xr-x. mysqladmin dba Nov : scripts
drwxr-xr-x. mysqladmin dba Nov : share
drwxr-xr-x. mysqladmin dba Nov : sql-bench
drwxr-xr-x. mysqladmin dba Nov : support-files
[mysqladmin@slave054 ~]$

  2、新建backup目录

[mysqladmin@slave054 ~]$ mkdir arch backup

  3、使用scripts安装mysql_install_db

[mysqladmin@slave054 ~]$ scripts/mysql_install_db
Installing MySQL system tables...-- :: [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
-- :: [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...-- :: [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
-- :: [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 slave054 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 ./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 [mysqladmin@slave054 ~]$

  注意:如果第3步骤中,报了一个

Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory #缺少libaio.so 包  错误,为了修正这个错误,就需要 先执行 如下命令,之后再切换回mysqladmin用户,继续执行第3步骤中的内容

  * 4-1、查看Linux version

[mysqladmin@slave054 ~]$ cat /proc/version
Linux version 3.10.0-1062.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Wed Aug 7 18:08:02 UTC 2019
[mysqladmin@slave054 ~]$

  * 4-2、gcc  (建议使用root用户进行操作)

[mysqladmin@slave054 ~]$ rpm -qa |grep gcc
gcc-c++-4.8.-.el7.x86_64
gcc-4.8.-.el7.x86_64
libgcc-4.8.-.el7.x86_64
gcc-gfortran-4.8.-.el7.x86_64
[mysqladmin@slave054 ~]$

  * 4-3、切换root用户,安装libaio 包

[mysqladmin@slave054 ~]$ su - root
Password:
Last login: Mon Nov :: CST on pts/
[root@slave054 ~]# yum -y install libaio
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.lzu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB :
extras | 2.9 kB :
updates | 2.9 kB :
Package libaio-0.3.-.el7.x86_64 already installed and latest version
Nothing to do
[root@slave054 ~]#
Loaded plugins: fastestmirror
Determining fastest mirrors
base-tn54 | 1.1 kB :
tn-appv1 | B :
updates-tn54 | B :
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package libaio.i386 :0.3.-3.2 set to be updated
---> Package libaio.x86_64 :0.3.-3.2 set to be updated
--> Finished Dependency Resolution Dependencies Resolved ==============================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================
Installing:
libaio i386 0.3.-3.2 base-tn54 k
libaio x86_64 0.3.-3.2 base-tn54 k Transaction Summary
==============================================================================================================================
Install Package(s)
Update Package(s)
Remove Package(s) Total download size: k
Downloading Packages:
(/): libaio-0.3.-3.2.i386.rpm | kB :
(/): libaio-0.3.-3.2.x86_64.rpm | kB :
------------------------------------------------------------------------------------------------------------------------------
Total kB/s | kB :
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libaio /
Installing : libaio / Installed:
libaio.i386 :0.3.-3.2 libaio.x86_64 :0.3.-3.2 Complete!

第一次安装libaio效果

  * 4-4、重新切换mysqladmin用户

[root@slave054 ~]# su - mysqladmin
Last login: Mon Nov :: CST on pts/
[mysqladmin@slave054 ~]$ pwd
/usr/local/mysql
[mysqladmin@slave054 ~]$

五、初始化db

[mysqladmin@slave054 ~]$ scripts/mysql_install_db  --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[mysqladmin@slave054 ~]$ scripts/mysql_install_db  --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Installing MySQL system tables...-- :: [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
-- :: [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...-- :: [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
-- :: [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 slave054 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@slave054 ~]$

执行后的效果

六、配置mysql 自启服务

  1、切换root用户

[mysqladmin@slave054 ~]$ su - root
Password:
Last login: Mon Nov :: CST on pts/
[root@slave054 ~]#

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

[root@slave054 ~]# cd /usr/local/mysql
[root@slave054 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
[root@slave054 mysql]#

  3、赋予可执行权限

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

  4、添加服务

  这里为了防止之前安装过mysql服务,而导致此处不成功,这里先删除服务之后再安装服务。

[root@slave054 mysql]# chkconfig --del mysql
[root@slave054 mysql]# chkconfig --add mysql
[root@slave054 mysql]# chkconfig --level mysql on
[root@slave054 mysql]#

  5、写入便捷操作

[root@slave054 mysql]# echo 'su - mysqladmin -c "/etc/init.d/mysql start --federated"' >>/etc/rc.local
[root@slave054 mysql]# tail /etc/rc.local
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot. touch /var/lock/subsys/local
su - mysqladmin -c "/etc/init.d/mysql start --federated"
[root@slave054 mysql]#

七、启动mysql 服务

  1、切换mysqladmin用户

[root@slave054 mysql]# su - mysqladmin
Last login: Mon Nov :: CST on pts/
[mysqladmin@slave054 ~]$ pwd
/usr/local/mysql
[mysqladmin@slave054 ~]$
建议不执行

[mysqladmin@slave054 ~]$ ll
total
drwxr-xr-x. mysqladmin dba Nov : arch
drwxr-xr-x. mysqladmin dba Nov : backup
drwxr-xr-x. mysqladmin dba Nov : bin
-rwxr-xr-x. mysqladmin dba Jan COPYING
drwxr-xr-x. mysqladmin dba Nov : data
drwxr-xr-x. mysqladmin dba Nov : docs
drwxr-xr-x. mysqladmin dba Nov : include
-rwxr-xr-x. mysqladmin dba Jan INSTALL-BINARY
drwxr-xr-x. mysqladmin dba Nov : lib
drwxr-xr-x. mysqladmin dba Nov : man
-rw-r--r--. mysqladmin dba Nov : my.cnf
-rw-r--r--. mysqladmin dba Nov : my-new.cnf
drwxr-xr-x. mysqladmin dba Nov : mysql-test
-rwxr-xr-x. mysqladmin dba Jan README
drwxr-xr-x. mysqladmin dba Nov : scripts
drwxr-xr-x. mysqladmin dba Nov : share
drwxr-xr-x. mysqladmin dba Nov : sql-bench
drwxr-xr-x. mysqladmin dba Nov : support-files
[mysqladmin@slave054 ~]$ mv my.cnf my.cnf.bak
[mysqladmin@slave054 ~]$ ll
total
drwxr-xr-x. mysqladmin dba Nov : arch
drwxr-xr-x. mysqladmin dba Nov : backup
drwxr-xr-x. mysqladmin dba Nov : bin
-rwxr-xr-x. mysqladmin dba Jan COPYING
drwxr-xr-x. mysqladmin dba Nov : data
drwxr-xr-x. mysqladmin dba Nov : docs
drwxr-xr-x. mysqladmin dba Nov : include
-rwxr-xr-x. mysqladmin dba Jan INSTALL-BINARY
drwxr-xr-x. mysqladmin dba Nov : lib
drwxr-xr-x. mysqladmin dba Nov : man
-rw-r--r--. mysqladmin dba Nov : my.cnf.bak
-rw-r--r--. mysqladmin dba Nov : my-new.cnf
drwxr-xr-x. mysqladmin dba Nov : mysql-test
-rwxr-xr-x. mysqladmin dba Jan README
drwxr-xr-x. mysqladmin dba Nov : scripts
drwxr-xr-x. mysqladmin dba Nov : share
drwxr-xr-x. mysqladmin dba Nov : sql-bench
drwxr-xr-x. mysqladmin dba Nov : support-files
[mysqladmin@slave054 ~]$ mysqld_safe &
[]
[mysqladmin@slave054 ~]$ :: mysqld_safe Logging to '/usr/local/mysql/data/hostname.err'.
:: mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
^C
[mysqladmin@slave054 ~]$ ps -ef|grep mysqld
mysqlad+ : pts/ :: /bin/sh /usr/local/mysql/bin/mysqld_safe
mysqlad+ : pts/ :: /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=
mysqlad+ : pts/ :: grep --color=auto mysqld
[mysqladmin@slave054 ~]$ 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.)
tcp6 ::: :::* LISTEN /mysqld
[mysqladmin@slave054 ~]$ mv my.cnf.bak my.cnf

安全与监听-演示

  2、启动mysql 服务

[mysqladmin@slave054 ~]$  service mysql start
Starting MySQL SUCCESS!
[mysqladmin@slave054 ~]$ service mysql status
SUCCESS! MySQL running ()
[mysqladmin@slave054 ~]$

  

  3、登录mysql

[mysqladmin@slave054 ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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 |
| test |
+--------------------+
rows in set (0.00 sec) mysql>

 

*八、数据库部分被隐匿-解决方法 

  这里Database只有 information_schema 和 test,说明mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的''@'localhost'可以看出来

  1、先停止服务,并mysqld_safe执行

[mysqladmin@slave054 ~]$ service mysql stop
Shutting down MySQL.. SUCCESS!
[mysqladmin@slave054 ~]$ service mysql status
ERROR! MySQL is not running
[mysqladmin@slave054 ~]$ mysqld_safe --skip-grant-table
:: mysqld_safe Logging to '/usr/local/mysql/data/hostname.err'.
:: mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

   2、新开克隆窗口,程序登录恢复正常:

[linux@slave054 ~]$ su - mysqladmin
Password:
Last login: Mon Nov :: CST on pts/
[mysqladmin@slave054 ~]$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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 |
+--------------------+
rows in set (0.00 sec) mysql>

  

  3、删除匿名登录

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
rows in set (0.00 sec) mysql> delete from user where USER='';
Query OK, rows affected (0.00 sec) mysql> FLUSH PRIVILEGES;
Query OK, rows affected (0.00 sec) mysql> \q
Bye
[mysqladmin@slave054 ~]$

九、修改登录密码

[mysqladmin@slave054 ~]$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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 |
+--------------------+
rows in set (0.00 sec) mysql> use mysql
Database changed
mysql> update user set password=password('') where user='root';
Query OK, rows affected (0.00 sec)
Rows matched: Changed: Warnings: mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| slave054 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| :: | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------+-------------------------------------------+
rows in set (0.00 sec) mysql> delete from user where user='';
Query OK, rows affected (0.00 sec) mysql> flush privileges;
Query OK, rows affected (0.00 sec) mysql>

  在一定程度上说,mysql 5.7版本之前的初次默认密码为空,mysql 5.7以后默认密码为随机数。

十、配置无主机登录

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
rows in set (0.00 sec) mysql> select host,user from user;
+-----------+------+
| host | user |
+-----------+------+
| 127.0.0.1 | root |
| :: | root |
| localhost | root |
| slave054 | root |
+-----------+------+
rows in set (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;
Query OK, rows affected (0.00 sec) mysql> select host,user from user;
+-----------+------+
| host | user |
+-----------+------+
| % | root |
| 127.0.0.1 | root |
| :: | root |
| localhost | root |
| slave054 | root |
+-----------+------+
rows in set (0.00 sec) mysql> delete from user where host !='%';
Query OK, rows affected (0.00 sec) mysql> flush privileges;
Query OK, rows affected (0.00 sec) mysql> quit
Bye
[mysqladmin@slave054 ~]$

  此时不能再使用mysql -uroot进行登录 ,而一定要使用 mysql -uroot -p进行登录,切记 -p后面不能写明密码,防止密码泄露!如:

[mysqladmin@slave054 ~]$ mysql -uroot
ERROR (): Access denied for user 'root'@'localhost' (using password: NO)
[mysqladmin@slave054 ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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>

十一、写入配置到用户个人环境变量文件

  ·这里不写/etc/profile的原因:mysqladmin用户专职进行mysql的管理,独自集中管理,拒绝权利外配,所以就连全局下的root不分配。

  ·这里不写.bash_profile的原因:在使用SecureCRT连接时,.bash_profile的部分配置参数不被加载

  所以经过分析,写入 .bashrc文件,将下列内容追加到 .bashrc文件中,切记先进入-- INSERT --  模式再粘贴,否则容易发生粘贴不完全的现象

# User specific environment and startup programs
MYSQL_BASE=/usr/local/mysql
export MYSQL_BASE
PATH=$PATH:${MYSQL_BASE}/bin:/usr/kerberos/bin:/opt/bin:/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/mysql
export PATH
export PATH unset USERNAME #stty erase
set umask to
umask
PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1 alias l="ls -ltr"
alias la="ls -la"
alias d="df -lk"
#alias rm="rm -i"
alias bg="ps -aef|grep mysql"
alias base="cd /usr/local/mysql"
alias bin="cd //usr/local/mysql/bin"
alias dba="cd /usr/local/mysql/dba"
alias sh="cd /usr/local/mysql/dba/sh"
alias sql="cd /usr/local/mysql/dba/sql"
alias config="cd /usr/local/mysql/dba/config"
alias dbalog="cd /usr/local/mysql/dba/log"
alias arch="cd /usr/local/mysql/arch"
alias data="cd /usr/local/mysql/data"

 这样重新登录mysqladmin用户,会改变mysqladmin的样式,方便生产过程:

[mysqladmin@slave054 ~]$ exit
logout
[linux@slave054 ~]$ su - mysqladmin
Password:
Last login: Mon Nov :: CST on pts/
slave054:mysqladmin:/usr/local/mysql:>

  注意:

    如果发生如下错误,对应修改即可:

Error1: File '/usr/local/mysql/arch/mysql-bin.index' not found (Errcode: )
test2.localdomain:mysqladmin:/usr/local/mysql/arch:>chmod *
test2.localdomain:mysqladmin:/usr/local/mysql/arch:>chown –R mysqladmin:dba *

十二、远程连接问题

见图:

  先登录root用户关闭防火墙

slave054:mysqladmin:/usr/local/mysql:>su - root
Password:
Last login: Mon Nov :: CST on pts/
[root@slave054 ~]# systemctl start firewalld
[root@slave054 ~]# systemctl stop firewalld
[root@slave054 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon -- :: CST; 8s ago
Docs: man:firewalld()
Process: ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=/SUCCESS)
Main PID: (code=exited, status=/SUCCESS) Nov :: slave054 systemd[]: Starting firewalld - dynamic firewall .....
Nov :: slave054 systemd[]: Started firewalld - dynamic firewall d...n.
Nov :: slave054 systemd[]: Stopping firewalld - dynamic firewall .....
Nov :: slave054 systemd[]: Stopped firewalld - dynamic firewall d...n.
Hint: Some lines were ellipsized, use -l to show in full.
[root@slave054 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@slave054 ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@slave054 ~]#

  再次测试连接成功,见图:

数据仓库006 - MySQL 5.6.x - Linux最佳生产环境离线部署的更多相关文章

  1. Linux上生产环境源码方式安装配置postgresql12

    1.Linux上源码方式安装postgresql12 01.准备操作系统环境 echo "192.168.1.61 tsepg61" >> /etc/hosts mou ...

  2. Linux企业生产环境用户权限集中管理项目方案案例

    企业生产环境用户权限集中管理项目方案案例: 1 问题现状 当前我们公司里服务器上百台,各个服务器上的管理人员很多(开发+运维+架构+DBA+产品+市场),在大家登录使用Linux服务器时,不同职能的员 ...

  3. Linux suse x86_64 环境上部署Hadoop启动失败原因分析

    一.问题症状: 在安装hadoop的时候报类似如下的错误: # A fatal error has beendetected by the Java Runtime Environment: # #  ...

  4. 保障MySQL安全的14个最佳方法

    MySQL数据库一贯以高性能.高可性和易用性著称,它已经成为世界上最流行的开源数据库.大量的个人.WEB开发者.大型公司等都在其网站.关键系统.软件包中广泛使用MySQL数据库.        通常, ...

  5. 将win平台上的mysql数据复制到linux上报错Can't write; duplicate key in table

    将win平台上的mysql数据复制到linux上报错Can't write; duplicate key in table xxx 新年新气象,果然在新年的第一天就遇到了一个大坑,项目在win上跑的没 ...

  6. 尚观Linux最佳入门高清视频教程033/133/253

    [高清]Linux 最佳入门ULE112- RHCE033部分高清视频教程[尚观原创] 视频简介:高清RHCE033部分是RHCE考试中的基础部分,同时也是我们Linux入门的必 备学习资料.想学好L ...

  7. MYSQL数据库常用的LINUX命令

    此为我工作中常用MYSQL数据库命令 LINUX系统中启动 / 重启MYSQL服务:service mysql start  /  service mysql restart(重启服务) LINUX系 ...

  8. Linux搭建Java环境(JDK+Tomcat+MySQL)

    目录 一.项目环境: 二.安装JDK1.8 三.安装Tomcat8.5 四.安装MySQL数据库 五.配置JAVA项目 一.项目环境: 开发环境 生产环境 测试环境 硬件环境: web服务器:cpu: ...

  9. MySQL连接处理方式及最佳并发连接数设置

    MySQL连接处理方式及最佳并发连接数设置 mysql是单进程,多线程的架构,通过创建多个线程来服务不同的用户连接,通常情况下,随着用户连接数的增加,mysql内部用于处理用户连接的线程也会同步的增长 ...

随机推荐

  1. Eclipse优化之设置不自动弹出控制台和Server

    有时候Eclipse启动,控制台console不会自动跳出来,需要手工点击该选项卡才行, 按下面的设置,可以让它自动跳出来(或不跳出来): windows  ->   preferences   ...

  2. 第04组 Beta冲刺(1/5)

    队名:new game 组长博客:戳 作业博客:戳 组员情况 鲍子涵(队长) 过去两天完成了哪些任务 验收游戏素材 学习Unity 2D Animation系统 接下来的计划 制作游戏需要的人物动画 ...

  3. vscode源码分析【四】程序启动的逻辑,最初创建的服务

    第一篇: vscode源码分析[一]从源码运行vscode 第二篇:vscode源码分析[二]程序的启动逻辑,第一个窗口是如何创建的 第三篇:vscode源码分析[三]程序的启动逻辑,性能问题的追踪 ...

  4. 05Shell循环语句

    循环语句 for 语法结构 for 变量名 [ in 取值列表 ] do 循环体 done 注意 当for对文件内容进行逐行处理时,会忽略空行 示例 例1 ping 主机的脚本(初始版):缺点执行过程 ...

  5. PHP JWT token实现

      原文链接:https://www.jb51.net/article/146790.htm   机制:   代码如下:   <?php /**  * PHP实现jwt  */ class Jw ...

  6. What is Java virtual machine?

    Java Virtual Machine (JVM) is a specification that provides runtime environment in which java  bytec ...

  7. Visual Studio 2019 16.1 使用 .NET Core 3.0

    一.前言 早在很久之前微软便公布 .NET Core 3.0 将支持开发Winform应用程序等等新特性,现如今 .NET Core 3.0 预览版已经出来第五个预览版了,从 .NET Core 2. ...

  8. Spring Cloud中Hystrix 线程隔离导致ThreadLocal数据丢失问题分析

    最近spring boot项目中由于使用了spring cloud 的hystrix 导致了threadLocal中数据丢失,其实具体也没有使用hystrix,但是显示的把他打开了,导致了此问题. 导 ...

  9. Z从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之九 || 依赖注入IoC学习 + AOP界面编程初探

    本文梯子 本文3.0版本文章 更新 代码已上传Github+Gitee,文末有地址 零.今天完成的绿色部分 一.依赖注入的理解和思考 二.常见的IoC框架有哪些 1.Autofac+原生 2.三种注入 ...

  10. Linux下正确修改Docker镜像和容器的默认存储位置,亲测有效

    我们通过 yum 的方式安装完Docker环境后,它默认的存储位置是 /var/lib/docker,默认的 pid 存放位置是 /var/run/docker.pid. 如果仅仅是做测试,我们可能没 ...