mysql创建多个实例,其实就是把DATA文件,SOCK,PORT指向不同的文件和端口
mysql安装过程看 http://blog.csdn.net/tangpengtao/article/details/6650424
先创建3307的DATA目录
[root@localhost mysql-5.5.15]# mkdir -p /usr/local/mysql3307
[root@localhost mysql-5.5.15]#
[root@localhost mysql-5.5.15]#
[root@localhost mysql-5.5.15]# chmod +w /usr/local/mysql3307
[root@localhost mysql-5.5.15]# chown -R mysql:mysql /usr/local/mysql3307
[root@localhost mysql-5.5.15]#
[root@localhost mysql-5.5.15]# mkdir -p /var/mysql3307/
mkdir -p /var/mysql3307/data/
mkdir -p /var/mysql3307/log/
chown -R mysql:mysql /var/mysql3307/
[root@localhost mysql-5.5.15]# mkdir -p /var/mysql3307/data/
[root@localhost mysql-5.5.15]# mkdir -p /var/mysql3307/log/
[root@localhost mysql-5.5.15]# chown -R mysql:mysql /var/mysql3307/
mkdir -p /usr/local/mysql3307
chmod +w /usr/local/mysql3307
chown -R mysql:mysql /usr/local/mysql3307
mkdir -p /var/mysql3307/
mkdir -p /var/mysql3307/data/
mkdir -p /var/mysql3307/log/
chown -R mysql:mysql /var/mysql3307/
[root@localhost mysql-5.5.15]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307 \
> -DMYSQL_UNIX_ADDR=/tmp/mysql3307.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/var/mysql3307/data \
> ;
-- MySQL 5.5.15
-- Configuring done
-- Generating done
-- Build files have been written to: /home/raycloud/software/mysql-5.5.15
[root@localhost mysql-5.5.15]#
[root@localhost mysql-5.5.15]# make
-- MySQL 5.5.15
-- Configuring done
-- Generating done
-- Build files have been written to: /home/raycloud/software/mysql-5.5.15
[ 0%] Built target INFO_BIN
[root@localhost mysql-5.5.15]# make install
mysql 初始化安装
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql
进入到my.cnf然后vi my.cnf
[mysqld3]
port = 3307
socket = /tmp/mysql3307.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
#wait_timeout=100
#interactive_timeout=100
max_connections=1400
user=root
datadir=/var/mysql3307/data
启动mysql
[root@localhost etc]# mysqld_safe --user=root --port=3307 --socket=/tmp/mysql3307.sock --datadir=/var/mysql3307/data &
[2] 7459
[root@localhost etc]# Starting mysqld daemon with databases from /var/mysql3307/data
查看mysql服务是否启动
[root@localhost etc]# ps -ef |grep 3307
root 7459 1624 0 20:18 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe --user=root --port=3307 --socket=/tmp/mysql3307.sock --datadir=/var/mysql3307/data
root 7488 7459 0 20:18 pts/1 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/mysql3307/data --user=root --pid-file=/var/mysql3307/data/localhost.localdomain.pid --skip-external-locking --port=3307 --socket=/tmp/mysql3307.sock
root 7502 1624 0 20:19 pts/1 00:00:00 grep 3307
[root@localhost etc]#
进入mysqlclient 修改密码
[root@localhost etc]# mysql -uroot --socket=/tmp/mysql3307.sock --port=3307 -p
Enter password:
mysql> use mysql;
Database changed
mysql> update user set password=password('yourpassword') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_results=utf8
->
->
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql>
停止mysql 3307
[root@localhost etc]# mysqladmin -uroot --socket=/tmp/mysql3307.sock --port=3307 -p shutdown
Enter password:
[root@localhost etc]#
启动3307数据库
[root@localhost etc]# /usr/local/mysql/bin/mysqld_multi --defaults-file=/etc/my.cnf start 3
Tags - mysql , mysql安装
--转自