1.上传mysql5.6.23安装包到/usr/local/目录下
cd /usr/local
rz命令上传mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
2.解压安装包,和修改名字
tar -zxvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql
3.创建用户组和用户
groupadd -g 101 dba
useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
4.copy 环境变量配置文件至mysqladmin用户的home目录中,为了以下步骤配置个人环境变量
cp /etc/skel/.* /usr/local/mysql
5.修改/etc/my.cnf配置文件
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
生产上
innodb_buffer_pool_size = 2048M(可以调大,一般是8G-12G都可以)
6.改变my.cmf的权限
chown mysqladmin:dba /etc/my.cnf
chmod 640 /etc/my.cnf
7.改变/usr/local/mysql目录权限
chown -R mysqladmin:dba /usr/local/mysql
chmod -R 755 /usr/local/mysql
注意:关于文件夹的修改 修改完成后 一定要cd进去 ll再看一下
8.创建binlog日志存储文件
[root@ruozedata001 ~]# su - mysqladmin
Last login: Fri Jun 28 14:01:40 CST 2019 on pts/2
ruozedata001:mysqladmin:/usr/local/mysql:>pwd
/usr/local/mysql
ruozedata001:mysqladmin:/usr/local/mysql:>mkdir arch
9.执行安装脚本文件
scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
报错: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 包
yum -y install libaio(安装libaio包)
scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
然后再执行上述安装命令
10.配置mysql服务的自动启动
#将服务文件拷贝到init.d下,并重命名为mysql
[root@ruozedata001 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
#赋予可执行权限
[root@ruozedata001 mysql]# chmod +x /etc/rc.d/init.d/mysql
#删除服务
[root@ruozedata001 mysql]# chkconfig --del mysql
#添加服务
[root@ruozedata001 mysql]# chkconfig --add mysql
[root@ruozedata001 mysql]# chkconfig --level 345 mysql on
[root@ruozedata001 mysql]# vi /etc/rc.local(开机最先读取的配置文件)
su - mysqladmin -c "/etc/init.d/mysql start"
11.修改环境变量
ruozedata001:mysqladmin:/usr/local/mysql:>cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export MYSQL_HOME=/usr/local/mysql
export PATH=${MYSQL_HOME}/bin:$PATH
unset USERNAME
set unmask to 022
umask 022
PS1=`uname -n`":"'$USER'":"'$PWD'":>";
export PS1
ruozedata001:mysqladmin:/usr/local/mysql:>
12.然后启动mysql
ruozedata001:mysqladmin:/usr/local/mysql:>/etc/init.d/mysql start
Starting MySQL. SUCCESS!
ruozedata001:mysqladmin:/usr/local/mysql:>
注意:这里必须要切换到mysqladmin这个服务才能够启动mysql
13登陆mysql并删除空用户和修改mysql的root用户的密码
ruozedata001:mysqladmin:/usr/local/mysql:>mysql -uroot -p
Enter password:
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>
mysql> use mysql;
Database changed
mysql> delete from user where user='';
mysql> update user set password=password('123456') where user='root';
mysql>flush privileges;
注意:只要mysql数据库已装好,就最好删除空用户和修改root的密码,不然会造成很多的bug,尤其是mysql数据库重新安装了后
14.mysql数据库如果需要重新安装
service mysql stop
rm -rf /usr/local/mysql/arch/*
rm -rf /usr/local/mysql/data/*
scripts/mysql_install_db \
--user=mysqladmin \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
然后再好删除空用户和修改root的密码,不然会造成很多的bug.