天天看点

mysql端口3309_为mysql添加端口号为3309的实例:

为mysql添加端口号为3309的实例:

一 添加新端口的数据目录:mkdir /usr/local/mysql/var1

二 修改my.cnf的配置信息:

1将client的默认端口3306注释掉

[client]

#password       = your_password

#port           = 3306

socket          = /tmp/mysql.sock

2  添加mysqld_multi配置信息

[mysqld_multi]

mysqld = /usr/local/mysql/bin/mysqld_safe

mysqladmin = /usr/local/mysql/bin/mysqladmin

user = root

#password = root

3 添加新实例对应的端口及参数信息:

[mysqld2]

user            = mysql

port      = 3309

socket    = /tmp/mysql1.sock

pid-file=/usr/local/mysql/var1/db-app1.pid

log=/usr/local/mysql/var1/db-app1.log

datadir = /usr/local/mysql/var1/

basedir = /usr/local/mysql

user = root

三 初始化数据目录 为新端口安装数据库:(也可以将mysql原来的数据文件目录cp过来 cp /usr/local/mysql/var  /usr/local/mysql/var2  chown ...chgrp...)

sudo /usr/local/mysql/bin/mysql_install_db --datadir=/usr/local/mysql/var1 --user=mysql

四 修改var1的用户及用户组: (注意 修改权限必须要再安装mysql数据库之后)

sudo chown -R mysql var1

sudo chgrp -R mysql var1

配置多实例启动脚本

cp /home/sunny.zhao/ mysql-5.1.51/support-files/mysqld_multi.server /etc/init.d/mysqld_multi.server

检查mysqld_multi.server 的 basedir和bindir安装路径basedir=/usr/local/mysqlbindir=/usr/local/mysql/bin

六  关闭mysql服务 mysqladmin -uroot -p*** shutdown

#查看数据库状态#结果都为没有运行Reporting MySQL serversMySQL server from group: mysqld1 is not runningMySQL server from group: mysqld2 is not running

sudo mysqld_multi --defaults-extra-file=/etc/my.cnf start

#启动具体某一个实例可在start、stop后面加上具体数据1,2,3等

sudo mysqld_multi --defaults-extra-file=/etc/my.cnf report

登录端口为3309mysql实例: mysql -uroot -p -h127.0.0.1 -P3309

#通过sock文件登录mysql -uroot -p -S /usr/local/var/mysql1/mysql1.sock #查看socket文件mysql> SHOW VARIABLES LIKE 'socket';

+---------------+------------------+

| Variable_name | Value            |

+---------------+------------------+

| socket        | /tmp/mysql1.sock |

+---------------+------------------+

1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE '%pid%';

+---------------+-----------------------------------+

| Variable_name | Value                             |

+---------------+-----------------------------------+

| pid_file      | /usr/local/mysql/var1/db-app1.pid |

+---------------+-----------------------------------+

1 row in set (0.00 sec)

mysqld_multi stop 1,2 关闭1,2数据库。

sudo mysqld_multi --defaults-extra-file=/etc/my.cnf stop 1-2

或者  $ sudo mysqladmin -uroot -pmysql -P3312 -h127.0.0.1 shutdown

修改密码: bin]$ mysqladmin -uroot -P3309 -h127.0.0.1  password ***

登录:bin]$  mysql -uroot -pmysql -h127.0.0.1 -P3309

检查MySQL启动状态

netstat -ntlp | grep 33   查看MySQL端口启动状态

[ bin]$ netstat -ntl | grep 33

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:3309                0.0.0.0:*                   LISTEN

ls -l /tmp/*sock*      查看MySQL访问连接

y bin]$ ls -l /tmp/*sock*

srwxrwxrwx 1 root  root  0 Sep 19 09:08 /tmp/mysql1.sock

srwxrwxrwx 1 mysql mysql 0 Jul 20 14:50 /tmp/mysql2.sock

srwxrwxrwx 1 mysql mysql 0 Sep 19 10:16 /tmp/mysql.sock

srwxrwxrwx 1 root  root  0 Sep 19 10:13 /tmp/mysql.sock2

ps -ef | grep mysql     查看MySQL实例进程

root      7281     1  0 10:13 pts/5    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --socket=/tmp/mysql.sock2 --port=3309 --pid-file=/usr/local/mysql/var1/hostname.pid2 --datadir=/usr/local/mysql/var1 --user=root --socket=/tmp/mysql.sock2 --port=3309 --pid-file=/usr/local/mysql/var1/hostname.pid2 --datadir=/usr/local/mysql/var1 --user=root

root      7453  7281  0 10:13 pts/5    00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var1 --user=root --log-error=/usr/local/mysql/var1/mysql-test-woody.err --pid-file=/usr/local/mysql/var1/hostname.pid2 --socket=/tmp/mysql.sock2 --port=3309

root      7838     1  0 10:16 pts/5    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --port=3306 --socket=/tmp/mysql.sock --skip-external-locking --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/var/ .... --pid-file=/usr/local/mysql/var/mysql.pid

--log-error=/usr/local/mysql/var/mysql.err --pid-file=/usr/local/mysql/var/mysql.pid --socket=/tmp/mysql.sock --port=3306

不知道为什么用top命令查看进程的时候为什么只能看到一个 看不到两个进程 ???????

[*@*top]

8216 mysql     20   0  168m  28m 3872 S  0.0  2.9   0:00.34 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/var/ --user=mysql --skip-external-locking --key_b相关不错的博文:http://alicsd.iteye.com/blog/856939