当前位置:Gxlcms > mysql > 利用rpm包手把手教你安装MySQL5.6.23

利用rpm包手把手教你安装MySQL5.6.23

时间:2021-07-01 10:21:17 帮助过:45人阅读

利用rpm包手把手教你安装MySQL(MySQL-server-5.6.23 for CentOS6.5_64bit)

利用rpm包手把手教你安装MySQL(MySQL-server-5.6.23 for CentOS6.5_64bit)

一、检查操作系统上是否安装了MySQL
[root@mydb1 backup]# rpm -qa |grep mysql
qt-mysql-4.6.2-26.el6_4.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
mysql-devel-5.1.71-1.el6.x86_64
mysql-libs-5.1.71-1.el6.x86_64


二、删除MyQL(RedHat6.3服务器自带的mysql-libs是mysql-libs-5.1.61-4.el6.x86_64,可能会和高版本的mysql-libs有冲突)
yum remove mysql-libs

三、RPM安装MySQL(用root用户安装,不需要提前建mysql组和mysql用户,安装mysql-server过程中会自动创建)
[root@mydb1 backup]# rpm -pql MySQL-server-5.6.23-1.el6.x86_64.rpm | more
[root@mydb1 backup]# rpm -ivh MySQL-server-5.6.23-1.el6.i686.rpm
[root@mydb1 backup]# rpm -ivh MySQL-client-5.6.23-1.el6.x86_64.rpm

四、创建安装目录
mkdir -p /u01/app/mysql/data/mysql3306/data
mkdir -p /u01/app/mysql/data/mysql3306/log
mkdir -p /u01/app/mysql/log/mysql3306/iblog
mkdir -p /u01/app/mysql/log/mysql3306/binlog
mkdir -p /u01/app/mysql/data/mysql3306/tmp

五、配置my.cnf
cp /usr/my.cnf /u01/app/mysql/data/mysql3306/my.cnf


vi /u01/app/mysql/data/mysql3306/my.cnf
[client]
port=3306
socket=/u01/app/mysql/data/mysql3306/run/mysql.sock


[mysql]
port=3306
promprt=\\u@\\d \\r:\\m:\\s>


[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
explicit_defaults_for_timestamp=true


#dir
innodb_log_group_home_dir=/u01/app/mysql/log/mysql3306/iblog
innodb_data_home_dir=/u01/app/mysql/log/mysql3306/iblog
basedir=/usr
datadir=/u01/app/mysql/data/mysql3306/data
tmpdir=/u01/app/mysql/data/mysql3306/tmp
slave_load_tmpdir=/u01/app/mysql/data/mysql3306/tmp
log-error=/u01/app/mysql/data/mysql3306/log/alert.log
slow_query_log_file=/u01/app/mysql/data/mysql3306/log/slow.log
relay_log_info_file=/u01/app/mysql/log/mysql3306/binlog/relay-log.info
master-info-file=/u01/app/mysql/log/mysql3306/binlog/master.info
socket=/u01/app/mysql/data/mysql3306/run/mysql.sock
log-bin=/u01/app/mysql/log/mysql3306/binlog/binlog
relay-log=/u01/app/mysql/log/mysql3306/binlog/relaylog


innodb_force_recovery=0

四、执行MySQL安装脚本
sh init3306.sh


rm -rf /u01/app/mysql/mysql3306/data/*
rm -rf /u01/app/mysql/log/mysql3306/iblog/*
rm -rf /u01/app/mysql/log/mysql3306/binlog/*
chmod -R 777 /u01/app/mysql/data/mysql/3306/data/*
chmod -R 777 /u01/app/mysql/log/mysql3306/iblog/*
chmod -R 777 /u01/app/mysql/log/mysql3306/binlog/*
chmod 755 /u01/app/mysql/data/mysql3306/my.cnf
mysql_install_db --defaults-file=/u01/app/mysql/data/mysql3306/my.cnf --basedir=/usr/ --datadir=/u01/app/mysql/data/mysql3306/data

五、查是否有MySQL服务,如没有添加mysql到服务开机启动
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
查看开机启动设置是否成功
[root@mydb1 ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off

六、启动MySQL
[root@mydb1 ~]# service mysql start
Starting MySQL SUCCESS!

七、查看MySQL运行状态的方法
[root@mydb1 ~]# service mysql status
SUCCESS! MySQL running (4104)

八、查MySQL初始密码
[root@mydb1 ~]# cat /root/.mysql_secret
# The random password set for the root user at Mon Mar 30 15:04:58 2015 (local time): B15xIBTq3xAoGRVx


九、登录MySQL
[root@mydb1 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.23


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> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('guoyJoe123');
Query OK, 0 rows affected (0.00 sec)


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)


如果要远程访问root用户,如下命令!
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'guoyJoe123' WITH GRANT OPTION;

my.cnf参考:

MySQL系统参数配置

先不启动MySQL,,拷贝数据目录到新的位置/mysqldata/mysql_data/,并修改权限

cd /var/lib/mysql/

cp -r * /mysqldata/mysql_data/

[root@wmserpmysql1 /]# chown mysql:mysql -R /mysqldata

删除原来默认的参数文件

[root@wmserpmysql1 mysql]# rm /usr/my.cnf

rm: remove regular file `/usr/my.cnf'? y

重新拷贝新的参数文件,然后修改

[root@wmserpmysql1 mysql]# pwd

/usr/share/mysql

[root@wmserpmysql1 mysql]# cp my-default.cnf /etc/my.cnf

修改参数文件/etc/my.cnf

[client]

port = 3306

socket = /tmp/mysql.sock

[mysql]

no-auto-rehash

[mysqld]

port = 3306

socket = /tmp/mysql.sock

datadir=/mysqldata/mysql_data

skip-name-resolve

character-set-server=utf8

lower_case_table_names=1

expire-logs-days=60

back_log = 500

max_connections = 5000

max_connect_errors =100000

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 1M

max_heap_table_size = 64M

sort_buffer_size = 8M

join_buffer_size = 8M

thread_cache_size = 8

thread_concurrency =16

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

thread_stack = 192K

tmp_table_size = 64M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log_file=/mysqldata/mysql_data/localhost-slow.log

slow_query_log

long_query_time=1

relay-log=/mysqldata/mysql_data/relay-bin

server-id = 1

key_buffer_size = 32M

myisam_repair_threads = 1

myisam_recover

transaction_isolation = REPEATABLE-READ

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 10G

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_per_table=1

innodb_file_io_threads = 4

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 8M

innodb_log_file_size = 256M

innodb_log_files_in_group = 6

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

innodb_flush_method=O_DIRECT

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqldump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer_size = 512M

sort_buffer_size = 512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 65535

log-error=/mysqldata/mysql_data/wmserpmysql1.800best.com.err

pid-file=/mysqldata/mysql_data/wmserpmysql1.800best.com.pid

--------------------------------------分割线 --------------------------------------

Ubuntu 14.04下安装MySQL

《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主从服务器

Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群

Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb

MySQL-5.5.38通用二进制安装

--------------------------------------分割线 --------------------------------------

本文永久更新链接地址

人气教程排行