Install Multiple MySQL instances in Linux

Source: Internet
Author: User
Tags localhost mysql

When MySQL creates multiple instances, it actually points the data file, sock, and port to different files and ports.

MySQL installation process see http://blog.csdn.net/tangpengtao/article/details/6650424

Create a 3307 data directory first

[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
-- Processing ing 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
-- Processing ing done
-- Generating done
-- Build files have been written to:/home/raycloud/software/mysql-5.5.15
[2, 0%] built target info_bin

[Root @ localhost mysql-5.5.15] # make install

MySQL initialization and Installation

/Usr/local/MySQL/scripts/mysql_install_db \
-- Defaults-file =/etc/My. CNF \
-- Basedir =/usr/local/MySQL \
-- Datadir =/var/MySQL/data \
-- User = MySQL

Go to my. CNF and then VI my. CNF.

[Mysqld3]
Port = 3307
Socket =/tmp/mysql3307.sock
Skip-external-locking
Key_buffer_size = 256 m
Max_allowed_packet = 1 m
Table_open_cache = 256
Sort_buffer_size = 1 m
Read_buffer_size = 1 m
Read_rnd_buffer_size = 4 m
Myisam_sort_buffer_size = 64 m
Thread_cache_size = 8
Query_cache_size = 16 m
# Wait_timeout = 100
# Interactive_timeout = 100
Max_connections = 1400
User = root
Datadir =/var/mysql3307/Data

Start 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

Check whether the MySQL service is started

[Root @ localhost, etc] # ps-Ef | grep 3307
Root 7459 1624 0 00:00:00 pts/1/bin/sh/usr/bin/mysqld_safe -- user = root -- Port = 3307 -- socket =/tmp/mysql3307.sock -- datadir =/var/ mysql3307/Data
Root 7488 7459 0 00:00:00 pts/1/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 00:00:00 pts/1 grep 3307
[Root @ localhost etc] #

Go to mysqlclient to change the password

[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>

Stop MySQL 3307

[Root @ localhost etc] # mysqladmin-uroot -- socket =/tmp/mysql3307.sock -- Port = 3307-P Shutdown
Enter password:
[Root @ localhost etc] #

Start database 3307
[Root @ localhost etc] #/usr/local/MySQL/bin/mysqld_multi -- defaults-file =/etc/My. CNF start 3

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.