服务器启动程序帮助命令:
mysqld --verbose --help
mysqld --verbose --help |grep 关键字
mysqld --verbose --help |grep skip
[root@student ~]# mysqld --verbose --help |grep skip |tail -6
2023-10-14T13:53:39.051831Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
skip-grant-tables FALSE
skip-name-resolve FALSE
skip-networking FALSE
skip-show-database FALSE
skip-slave-start FALSE
slave-skip-errors (No default value)
mysqld_safe — MySQL 服务器启动脚本,服务器启动程序安全模式
mysqld_safe:
Table 4.6 mysqld_safe Options
Option Name | Description |
---|---|
--basedir | Path to MySQL installation directory |
--core-file-size | Size of core file that mysqld should be able to create |
--datadir | Path to data directory |
--defaults-extra-file | Read named option file in addition to usual option files |
--defaults-file | Read only named option file |
--help | Display help message and exit |
--ledir | Path to directory where server is located |
--log-error | Write error log to named file |
--malloc-lib | Alternative malloc library to use for mysqld |
--mysqld | Name of server program to start (in ledir directory) |
--mysqld-safe-log-timestamps | Timestamp format for logging |
--mysqld-version | Suffix for server program name |
--nice | Use nice program to set server scheduling priority |
--no-defaults | Read no option files |
--open-files-limit | Number of files that mysqld should be able to open |
--pid-file | Path name of server process ID file |
--plugin-dir | Directory where plugins are installed |
--port | Port number on which to listen for TCP/IP connections |
--skip-kill-mysqld | Do not try to kill stray mysqld processes |
--skip-syslog | Do not write error messages to syslog; use error log file |
--socket | Socket file on which to listen for Unix socket connections |
--syslog | Write error messages to syslog |
--syslog-tag | Tag suffix for messages written to syslog |
--timezone | Set TZ time zone environment variable to named value |
--user | Run mysqld as user having name user_name or numeric user ID user_id |
在/etc/init.d/目录下
mysql.server start
mysql.server stop
如果您从源代码发行版或使用 二进制分发格式,不会自动安装MySQL.Server,您可以 手动安装脚本。它可以在MySQL下的安装目录support-files/
中找到。复制脚本到目录/etc/init.d
:
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
在某些 Linux 系统上,以下命令似乎也 是完全启用 MySQL 脚本所必需的:
chkconfig --level 345 mysql on
mysql.server从选项文件的[mysql.server]和[mysqld]部分读取选项。为了向后兼容性,它还读取[mysql_server]部分,但要保持最新,您应该将这些部分重命名为[mysql.server]。
典型的/etc/my.cnf
my.cnf
文件可能如下所示:
[mysqld]
datadir=/usr/local/mysql/var
socket=/var/tmp/mysql.sock
port=3306
user=mysql
[mysql.server]
basedir=/usr/local/mysql
mysqld_multi — 管理多个 MySQL 服务器
mysqld_multi在my.cnf(或--defaults file选项命名的文件)中搜索名为[mysqldN]的组。N可以是任何正整数。在下面的讨论中,这个数字被称为选项组号或GNR。组号将选项组彼此区分开来,并用作mysqld_multi的参数,以指定要启动、停止或获取状态报告的服务器。这些组中列出的选项与您在用于启动mysqld的[mysqld]组中使用的选项相同。
mysqld_multi --example
[root@student ~]# mysqld_multi --example
# This is an example of a my.cnf file for mysqld_multi.
# Usually this file is located in home dir ~/.my.cnf or /etc/my.cnf
#
# SOME IMPORTANT NOTES FOLLOW:
#
# 1.COMMON USER
#
# Make sure that the MySQL user, who is stopping the mysqld services, has
# the same password to all MySQL servers being accessed by mysqld_multi.
# This user needs to have the 'Shutdown_priv' -privilege, but for security
# reasons should have no other privileges. It is advised that you create a
# common 'multi_admin' user for all MySQL servers being controlled by
# mysqld_multi. Here is an example how to do it:
#
# GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'password'
#
# You will need to apply the above to all MySQL servers that are being
# controlled by mysqld_multi. 'multi_admin' will shutdown the servers
# using 'mysqladmin' -binary, when 'mysqld_multi stop' is being called.
#
# 2.PID-FILE
#
# If you are using mysqld_safe to start mysqld, make sure that every
# MySQL server has a separate pid-file. In order to use mysqld_safe
# via mysqld_multi, you need to use two options:
#
# mysqld=/path/to/mysqld_safe
# ledir=/path/to/mysqld-binary/
#
# ledir (library executable directory), is an option that only mysqld_safe
# accepts, so you will get an error if you try to pass it to mysqld directly.
# For this reason you might want to use the above options within [mysqld#]
# group directly.
#
# 3.DATA DIRECTORY
#
# It is NOT advised to run many MySQL servers within the same data directory.
# You can do so, but please make sure to understand and deal with the
# underlying caveats. In short they are:
# - Speed penalty
# - Risk of table/data corruption
# - Data synchronising problems between the running servers
# - Heavily media (disk) bound
# - Relies on the system (external) file locking
# - Is not applicable with all table types. (Such as InnoDB)
# Trying so will end up with undesirable results.
#
# 4.TCP/IP Port
#
# Every server requires one and it must be unique.
#
# 5.[mysqld#] Groups
#
# In the example below the first and the fifth mysqld group was
# intentionally left out. You may have 'gaps' in the config file. This
# gives you more flexibility.
#
# 6.MySQL Server User
#
# You can pass the user=... option inside [mysqld#] groups. This
# can be very handy in some cases, but then you need to run mysqld_multi
# as UNIX root.
#
# 7.A Start-up Manage Script for mysqld_multi
#
# In the recent MySQL distributions you can find a file called
# mysqld_multi.server.sh. It is a wrapper for mysqld_multi. This can
# be used to start and stop multiple servers during boot and shutdown.
#
# You can place the file in /etc/init.d/mysqld_multi.server.sh and
# make the needed symbolic links to it from various run levels
# (as per Linux/Unix standard). You may even replace the
# /etc/init.d/mysql.server script with it.
#
# Before using, you must create a my.cnf file either in /usr/local/mysql/my.cnf
# or /root/.my.cnf and add the [mysqld_multi] and [mysqld#] groups.
#
# The script can be found from support-files/mysqld_multi.server.sh
# in MySQL distribution. (Verify the script before using)
#
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = multi_admin
password = my_password
[mysqld2]
socket = /tmp/mysql.sock2
port = 3307
pid-file = /usr/local/mysql/data2/hostname.pid2
datadir = /usr/local/mysql/data2
language = /usr/local/mysql/share/mysql/english
user = unix_user1
[mysqld3]
mysqld = /path/to/mysqld_safe
ledir = /path/to/mysqld-binary/
mysqladmin = /path/to/mysqladmin
socket = /tmp/mysql.sock3
port = 3308
pid-file = /usr/local/mysql/data3/hostname.pid3
datadir = /usr/local/mysql/data3
language = /usr/local/mysql/share/mysql/swedish
user = unix_user2
[mysqld4]
socket = /tmp/mysql.sock4
port = 3309
pid-file = /usr/local/mysql/data4/hostname.pid4
datadir = /usr/local/mysql/data4
language = /usr/local/mysql/share/mysql/estonia
user = unix_user3
[mysqld6]
socket = /tmp/mysql.sock6
port = 3311
pid-file = /usr/local/mysql/data6/hostname.pid6
datadir = /usr/local/mysql/data6
language = /usr/local/mysql/share/mysql/japanese
user = unix_user4
mysqld_multi start 2-4,6
mysqld_multi stop 2-4,6
使用 mysql 非常简单。从命令解释器的提示符输入如下:
mysql db_name
或:
mysql --user=user_name --password db_name
比如 登录db_1数据库
[root@student ~]# mysql db_1
mysql> show tables;
Empty set (0.00 sec)
mysql>
比如 登录MySQL数据库
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
mysql db_name < script.sql > output.tab
[root@student ~]# cat script.sql
show tables
[root@student ~]# mysql mysql < script.sql > output.tab
[root@student ~]# cat output.tab |tail -6
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user
[root@student ~]#
mysql支持以下选项,这些选项可以在命令行上指定,也可以在选项文件的[mysql]和[client]组中指定
mysql --verbose --help
mysql> help
help contents
mysql> help 命令
mysqladmin — 一个 MySQL 服务器管理程序
mysqlcheck — 表维护程序
mysqldump — 数据库备份程序
mysqlimport — 一个数据导入程序
mysqlpump — 数据库备份程序
mysqlshow — 显示数据库、表和列信息
mysqlslap — 负载仿真客户端