本文系统:rhel5.8
ip : 192.168.100.150
数据库版本:mysql-5.6.15
1、创建部署mysql服务账号:
[[email protected] ~]# useradd -d /opt/mysql mysql [[email protected] ~]# echo "mysql" |passwd --stdin mysql Changing password for user mysql. passwd: all authentication tokens updated successfully.
2、解压无需免装包:配置环境变量
[[email protected] ~]$ tar zxvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz [[email protected] ~]$ mv mysql-5.6.15-linux-glibc2.5-x86_64 mysql-5.6.15 [[email protected] mysql-5.6.15]$ vim ~/.bash_profile MYSQL_HOME=/opt/mysql/mysql-5.6.15 export MYSQL_HOME PATH=$MYSQL_HOME/bin:$PATH export PATH
3、配置多实例数据库配置文件
[[email protected] ~]# mkdir /Data_for_Mysql [[email protected] ~]# chown mysql.mysql -R /Data_for_Mysql/ [[email protected] ~]# su - mysql [[email protected] ~]$ mkdir -p /Data_for_Mysql/3301/data /Data_for_Mysql/3301/logs [[email protected] ~]$ touch /Data_for_Mysql/3301/my.cnf [[email protected] ~]$ mkdir -p /Data_for_Mysql/3302/data /Data_for_Mysql/3302/logs [[email protected] ~]$ touch /Data_for_Mysql/3302/my.cnf
目录结构:
[[email protected] Data_for_Mysql]$ pwd /Data_for_Mysql [[email protected] Data_for_Mysql]$ tree . |-- 3301 | |-- data | |-- logs | `-- my.cnf `-- 3302 |-- data |-- logs `-- my.cnf 6 directories, 2 files [[email protected] Data_for_Mysql]$
配置my.cnf ######本配置文件只供参考
[[email protected] 3301]$ vim /Data_for_Mysql/3301/my.cnf [client] port = 3301 socket = /Data_for_Mysql/3301/data/mysql.sock [mysqld] user=msql port=3301 bind-address=192.168.100.150 socket = /Data_for_Mysql/3301/data/mysql.sock.3301 pid-file = /Data_for_Mysql/3301/data/mysql.pid basedir = /opt/mysql/mysql-5.6.15 datadir = /Data_for_Mysql/3301/data server-id=1 log-bin=mysql-bin log-bin-index= mysql-bin.index # LOGGING log_error=/Data_for_Mysql/3301/logs/mysql-error.log slow_query_log_file= /Data_for_Mysql/3301/logs/mysql-slow.log slow_query_log=1 character-sets-dir = /opt/mysql/mysql-5.6.15/share/charsets back_log = 2000 max_connections = 1000 connect-timeout = 60 wait-timeout = 28800 net_buffer_length = 16384 max_allowed_packet = 64M thread_stack = 192K thread_cache_size = 20 thread_concurrency = 128 query_cache_size = 256M query_cache_limit = 2M query_cache_min_res_unit = 2 default-time-zone = system character-set-server = utf8 default-storage-engine = InnoDB tmp_table_size = 512M max_heap_table_size = 512M max_binlog_size = 1G max_relay_log_size = 1G [mysql] disable-auto-rehash default-character-set = utf8 [[email protected] 3301]$ vim my.cnf [[email protected] 3301]$ [[email protected] 3301]$ vim my.cnf [[email protected] 3301]$ [[email protected] 3301]$ cat my.cnf [client] port = 3301 socket = /Data_for_Mysql/3301/data/mysql.sock [mysqld] user=mysql port=3301 bind-address=192.168.100.150 socket = /Data_for_Mysql/3301/data/mysql.sock.3301 pid-file = /Data_for_Mysql/3301/data/mysql.pid basedir = /opt/mysql/mysql-5.6.15 datadir = /Data_for_Mysql/3301/data server-id=1 log-bin=mysql-bin log-bin-index= mysql-bin.index # LOGGING log_error=/Data_for_Mysql/3301/logs/mysql-error.log slow_query_log_file= /Data_for_Mysql/3301/logs/mysql-slow.log slow_query_log=1 character-sets-dir = /opt/mysql/mysql-5.6.15/share/charsets back_log = 2000 max_connections = 1000 connect-timeout = 60 wait-timeout = 28800 net_buffer_length = 16384 max_allowed_packet = 64M thread_stack = 192K thread_cache_size = 20 thread_concurrency = 128 query_cache_size = 256M query_cache_limit = 2M query_cache_min_res_unit = 2 default-time-zone = system character-set-server = utf8 default-storage-engine = InnoDB tmp_table_size = 512M max_heap_table_size = 512M max_binlog_size = 1G max_relay_log_size = 1G [mysql] disable-auto-rehash default-character-set = utf8
4、初始化数据库
[[email protected] scripts]$ pwd /opt/mysql/mysql-5.6.15/scripts [[email protected] scripts]$ ./mysql_install_db --defaults-file=/Data_for_Mysql/3301/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3301/data/
5、启动3301实例数据库 ###启动数据库必须在mysql目录;
[[email protected] mysql-5.6.15]$ pwd /opt/mysql/mysql-5.6.15 [[email protected] mysql-5.6.15]$ mysqld_safe --defaults-file=/Data_for_Mysql/3301/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3301/data/ & [[email protected] mysql-5.6.15]$ netstat -nat |grep 3301 tcp 0 0 192.168.100.150:3301 0.0.0.0:* LISTEN
Ps:3302 实例操作和上面一样,只需改动端口及相应目录即可;
3302配置文件:
[[email protected] 3302]$ cat my.cnf [client] port = 3302 socket = /Data_for_Mysql/3302/data/mysql.sock [mysqld] user=mysql port=3302 bind-address=192.168.100.150 socket = /Data_for_Mysql/3302/data/mysql.sock.3302 pid-file = /Data_for_Mysql/3302/data/mysql.pid basedir = /opt/mysql/mysql-5.6.15 datadir = /Data_for_Mysql/3302/data server-id=1 log-bin=mysql-bin log-bin-index= mysql-bin.index # LOGGING log_error=/Data_for_Mysql/3302/logs/mysql-error.log slow_query_log_file= /Data_for_Mysql/3302/logs/mysql-slow.log slow_query_log=1 character-sets-dir = /opt/mysql/mysql-5.6.15/share/charsets back_log = 2000 max_connections = 1000 connect-timeout = 60 wait-timeout = 28800 net_buffer_length = 16384 max_allowed_packet = 64M thread_stack = 192K thread_cache_size = 20 thread_concurrency = 128 query_cache_size = 256M query_cache_limit = 2M query_cache_min_res_unit = 2 default-time-zone = system character-set-server = utf8 default-storage-engine = InnoDB tmp_table_size = 512M max_heap_table_size = 512M max_binlog_size = 1G max_relay_log_size = 1G [mysql] disable-auto-rehash default-character-set = utf8
3302 实例初始化;
[[email protected] scripts]$ pwd /opt/mysql/mysql-5.6.15/scripts [[email protected] scripts]$ ./mysql_install_db --defaults-file=/Data_for_Mysql/3302/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3302/data/
3302 启动该实例:
[[email protected] mysql-5.6.15]$ mysqld_safe --defaults-file=/Data_for_Mysql/3302/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3302/data/ & [[email protected] mysql-5.6.15]$ netstat -nat |grep 330 tcp 0 0 192.168.100.150:3301 0.0.0.0:* LISTEN tcp 0 0 192.168.100.150:3302 0.0.0.0:* LISTEN
6、创建root密码,要区别实例
[[email protected] mysql-5.6.15]$ mysqladmin -uroot password ‘root123‘ -S /Data_for_Mysql/3301/data/mysql.sock.3301
6.1、关闭mysql,区别实例
[[email protected] mysql-5.6.15]$ mysqladmin -uroot -proot123 -S /Data_for_Mysql/3301/data/mysql.sock.3301 shutdown Warning: Using a password on the command line interface can be insecure. 150402 15:44:52 mysqld_safe mysqld from pid file /Data_for_Mysql/3301/data/mysql.pid ended [1]- Done mysqld_safe --defaults-file=/Data_for_Mysql/3301/my.cnf --user=mysql --basedir=/opt/mysql/mysql-5.6.15 --datadir=/Data_for_Mysql/3301/data/
时间: 2024-10-27 15:22:48