[root@nolinux ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/3306/data --user=mysql
WARNING: The host 'nolinux' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h nolinux password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
[root@nolinux ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/3307/data --user=mysql
WARNING: The host 'nolinux' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h nolinux password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
4、多实例的启动测试
[root@nolinux ~]# /usr/local/mysql/bin/mysqld_multi start # 默认start后面不跟数字,就表示全部实例都启动
[root@nolinux ~]# lsof -i tcp:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 31208 mysql 14u IPv4 81308 0t0 TCP *:mysql (LISTEN)
[root@nolinux ~]# lsof -i tcp:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 31208 mysql 14u IPv4 81308 0t0 TCP *:mysql (LISTEN)
补充:
仅启动某一个
[root@nolinux ~]# /usr/local/mysql/bin/mysqld_multi start 1 # 这里的1是我们在/etc/my.cnf中[mysqld1]标题中的数字,这个数字可以随便起,但是最好保证,数字是越来越大的!
5、多实例的关闭
[root@nolinux ~]# /usr/local/mysql/bin/mysql -S /mydata/3306/mysql.sock -e "grant shutdown on *.* to 'mysql'@'localhost' identified by 'sunsky'
[root@nolinux ~]# /usr/local/mysql/bin/mysql
-S /mydata/3307/mysql.sock -e "grant shutdown on *.* to 'mysql'@'localhost' identified by 'sunsky'
[root@nolinux ~]# /usr/local/mysql/bin/mysqld_multi stop
[root@nolinux ~]# netstat -lntup | grep 330
6、配置多实例的开机自启动
通过将 mysql 多实例的命令与对应的参数放入/etc/rc.local文件,来实现mysql多实例的开机自启动
[root@nolinux ~]# echo '# To start the mysql instance boot since 3306' >> /etc/rc.local
[root@nolinux ~]# echo '/usr/local/mysql/bin/mysqld_multi start 1' >> /etc/rc.local
[root@nolinux ~]# echo '# To start the mysql instance boot since 3307' >> /etc/rc.local
[root@nolinux ~]# echo '/usr/local/mysql/bin/mysqld_multi start 2' >> /etc/rc.local
[root@nolinux ~]# tail -4 /etc/rc.local
# To start the mysql instance boot since 3306
/usr/local/mysql/bin/mysqld_multi start 1
# To start the mysql instance boot since 3307
/usr/local/mysql/bin/mysqld_multi start 2
[root@nolinux ~]# mysqladmin -uroot password 'sunsky' -S /mydata/3308/mysql.sock
[root@nolinux ~]# mysql -uroot -psunsky -S /mydata/3306/mysql.sock << EOF
> drop database test;
> show databases;
> delete from mysql.user where user='root' and host='::1';
> delete from mysql.user where user='' and host='localhost';
> delete from mysql.user where user='' and host='nolinux';
> delete from mysql.user where user='root' and host='nolinux';
> select user,host from mysql.user;
> EOF
Database
information_schema
mysql
performance_schema
userhost
root127.0.0.1
mysqllocalhost
rootlocalhost
[root@nolinux ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/3308/data --user=mysql
WARNING: The host 'nolinux' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h nolinux password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
[root@nolinux ~]# /usr/local/mysql/bin/mysql
-S /mydata/3308/mysql.sock -e "grant shutdown on *.* to 'mysql'@'localhost' identified by 'sunsky'
[root@nolinux ~]# /usr/local/mysql/bin/mysqld_multi stop 3
[root@nolinux ~]# netstat -lntup | grep 3308
6、配置多实例的开机自启动
[root@nolinux ~]# echo '# To start the mysql instance boot since 3308' >> /etc/rc.local
[root@nolinux ~]# echo '/usr/local/mysql/bin/mysqld_multi start 3' >> /etc/rc.local
[root@nolinux ~]# tail -2 /etc/rc.local
# To start the mysql instance boot since 3308
/usr/local/mysql/bin/mysqld_multi start 3
7、安全优化
[root@nolinux ~]# mysqladmin -uroot password 'sunsky' -S /mydata/3308/mysql.sock
[root@nolinux ~]# mysql -uroot -psunsky -S /mydata/3308/mysql.sock << EOF
> drop database test;
> show databases;
> delete from mysql.user where user='root' and host='::1';
> delete from mysql.user where user='' and host='localhost';
> delete from mysql.user where user='' and host='nolinux';
> delete from mysql.user where user='root' and host='nolinux';
> select user,host from mysql.user;
> EOF
Database
information_schema
mysql
performance_schema
userhost
root127.0.0.1
mysqllocalhost
rootlocalhost