本次安装的MySQL版本信息如下:mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz,如需要安装包,请留言。
MySQL部署方式:1.yum部署;2.二进制部署
1、上传文件包
2、检查是否安装Mysql
ps -ef | grep mysqld
rpm -qa | grep -i mysql
没有Mysql进程,表示未安装,安装包有个,但不用
3、解压并重命名
解压:tar -xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
重命名:mv mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz mysql
4、创建用户组和用户(生产环境中,使用的不可能是root,故只能分配组权限)
创建dba用户组:groupadd -g 101 dba
创建用户mysqladmin(主组dba;用户组为root,dba;家目录为/usr/local/mysql):useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
PS:红框内容表示,我们未将用户环境变量文件复制到设定的家目录中,需手动复制
5、修改mysqladmin用户密码并复制环境变量配置文件到mysql用户的家目录
修改密码:passwd mysqladmin
复制变量:cp /etc/skel/.* /usr/local/mysql
6、创建配置文件(权限640)
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 = 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
7、修改用户组和权限
chown mysqladmin:dba /etc/my.cnf
chmod 640 /etc/my.cnf
chown -R mysqladmin:dba /usr/local/mysql
chmod -R 755 /usr/local/mysql
mkdir arch
用于装归档文件
8、第一次安装
/usr/local/mysql/scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
没有报错,说明安装成功
删除家目录中的my.cnf,以免造成勿扰
9、配置Mysql服务启动,查看进程并启动
cd /usr/local/mysql
#将服务文件拷贝到ini.d,并重命名
cp support-files/mysql.server /etc/rc.d/init.d/mysql
#赋予可执行权限
chmod +x /etc/rc.d/init.d/mysql
#若之前安装服务,需先删除服务,本次省略
#添加服务
chkconfig --add mysql
#设置启动级别345
chkconfig --level 345 mysql on
[root@hadoop000 mysql]# vi /etc/rc.local
修改内容
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
su - mysqladmin -c "/etc/init.d/mysql start --federated"
"/etc/rc.local" 9L, 278C written
bin/mysqld_safe &
ps -ef | grep mysqld
netstat -tulup | grep mysql
service mysql status
[root@hadoop000 mysql]# su -mysqladmin
su: invalid option -- 'y'
Try `su --help' for more information.
[root@hadoop000 mysql]# su - mysqladmin
[mysqladmin@hadoop000 ~]$ pwd
/usr/local/mysql
[mysqladmin@hadoop000 ~]$ ls
arch COPYING docs INSTALL-BINARY man README share support-files
bin data include lib mysql-test scripts sql-bench
[mysqladmin@hadoop000 ~]$ bin/mysqld_safe &
[1] 3013
[mysqladmin@hadoop000 ~]$ 180528 18:43:43 mysqld_safe Logging to '/usr/local/mysql/data/hostname.err'.
180528 18:43:43 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[mysqladmin@hadoop000 ~]$ ps -ef|grep mysql
root 2537 2329 0 17:35 pts/0 00:00:00 su mysqladmin
root 2617 2558 0 17:54 pts/0 00:00:00 su mysqladmin
root 2879 2856 0 18:31 pts/0 00:00:00 su mysqladmin
root 2986 2956 0 18:42 pts/0 00:00:00 su - mysqladmin
514 3013 2987 0 18:43 pts/0 00:00:00 /bin/sh bin/mysqld_safe
514 3656 3013 2 18:43 pts/0 00:00:00 /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 3679 2987 0 18:44 pts/0 00:00:00 grep mysql
[mysqladmin@hadoop000 ~]$ ps -ef|grep mysqld
514 3013 2987 0 18:43 pts/0 00:00:00 /bin/sh bin/mysqld_safe
514 3656 3013 2 18:43 pts/0 00:00:00 /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 3682 2987 0 18:44 pts/0 00:00:00 grep mysqld
[mysqladmin@hadoop000 ~]$ 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 3656/mysqld
[mysqladmin@hadoop000 ~]$ service mysql status
MySQL running (3656) [ OK ]
[mysqladmin@hadoop000 ~]$ 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.
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.08 sec)
10、修改密码(登录MySQL以后,需要对数据库添加密码)
use mysql;
update user set Password=password('123456') where user='root';
delete from user where user='';
11、刷新权限(MySQL更新用户以后要刷新权限)
flush privileges;
12、配置环境变量
vi /urs/local/mysql/.bash_profile