MySQL的启动方式教程
MySQL常用启动方式:
windows 和linux 上都可以使用 mysql --help|grep my.cnf 过滤查看关于MySQL对应 配置文件my.cnf
[root@bqh-118 bin]# mysql --help|grep my.cnf
order of preference, my.cnf, $MYSQL\_TCP\_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
因我MySQL安装在/application目录下:
1、mysqld\_safe [root@bqh-118 /]# /application/mysql/bin/mysqld\_safe --defaults-file=/etc/my.cnf --user=root & 客户端连接: mysql --defaults-file=/etc/my.cnf or mysql -S /tm/mysql.sock 2、mysql.server
[root@bqh-118 mysql]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld\_safe /application/mysql/support-files/mysql.server #将默认路径替换成自定义安装路径
[root@bqh-118 mysql]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld #将生成的启动脚本拷贝到init.d目录下
[root@bqh-118 mysql]# chmod +x /etc/init.d/mysqld #授予可执行权限
[root@bqh-118 mysql]# lsof -i:3306 #查询mysql服务是否开启
[root@bqh-118 mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
启动mysql服务器:service mysql.server {start|stop|restart|reload|force-reload|status}
当然也可以让chkconfig来管理
客户端连接: mysql --defaults-file=/etc/my.cnf or mysql -S /tm/mysql.sock 3、多实例mysqld\_multi mkdir $MYSQL\_BASE/data2 cat <<-EOF>> /etc/my.cnf [mysqld\_multi] mysqld = /application/mysql/bin/mysqld\_safe mysqladmin = /application/mysql/bin/mysqladmin user = mysqladmin password = mysqladmin [mysqld3306] port = 3306 socket = /tmp/mysql3306.sock pid-file = /tmp/mysql3306.pid skip-external-locking key\_buffer\_size = 16M max\_allowed\_packet = 1M table\_open\_cache = 64 sort\_buffer\_size = 512K net\_buffer\_length = 8K read\_buffer\_size = 256K read\_rnd\_buffer\_size = 512K myisam\_sort\_buffer\_size = 8M basedir = /application/mysql datadir = /application/mysql/data [mysqld3307] port = 3307 socket = /tmp/mysql3307.sock pid-file = /tmp/mysql3307.pid skip-external-locking key\_buffer\_size = 16M max\_allowed\_packet = 1M table\_open\_cache = 64 sort\_buffer\_size = 512K net\_buffer\_length = 8K read\_buffer\_size = 256K read\_rnd\_buffer\_size = 512K myisam\_sort\_buffer\_size = 8M basedir = /application/mysql datadir = /application/mysql/data2 EOF #mysql -S /tmp/mysql3306.sock mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option; #mysql -S /tmp/mysql3307.sock mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option; 启动mysql服务器:/application/mysql/bin/mysqld\_multi --defaults-file=/etc/my.cnf start 3306-3307 关闭mysql服务器:/application/mysql/bin/mysqladmin shutdown 当然,也可以写脚本一键启动的。