linux中mysql在哪启动方式_linux下启动mysql的方法 | Soo Smart!

linux下mysql启动的方法有几种(windows和mac下启动比较方便):

mysqld — The MySQL Server

mysqld_safe — MySQL Server Startup Script

mysql.server — MySQL Server Startup Script

mysqld_multi — Manage Multiple MySQL Servers

当然还有通过service来起mysql server的。默认安装后会注册为service的,所以再重启机器后也mysql server也启动了的。这就能解释为什么机器重启后mysql client还能连接。

service mysqld start

service mysqld stop

service mysqld restart

这4种命令又有什么区别呢?什么情况下使用哪个命令?

mysqld就是mysql server的启动命令入口。mysqld管理所有对mysql data directory的访问。mysql data directory包含数据库, 表, 日志,状态文件等。当mysql server启动后,它监听所有的client网络链接,并代表它们访问data directory。mysql server有一系列system variables。这些系统变量可以在启动时设置,有些也可能在启动后运行时设置。它们都会改变server运行时的行为。它还有一系列的status variables。这些status变量可以查看mysql server运行时的性能状态。通过运行mysqld -verbose --help来查看所有的参数。

mysqld_safe: 这是unix系统中推荐的启动mysql server的方法。它添加了一些安全特性,比如说当server出现error时重启,以及log一些logging info到err日志中。mysqld_safe运行mysqld并重写了它的一些默认行为。mysqld_safe的option与mysqld的option大部分差不多。对不认识的option会传给mysqld。mysqld_safe可以读取所有[mysqld][server][mysqld_safe][safe_mysqld]下的option。mysqld_safe会查找并读取--log-error这个参数,这样以后log信息都会写到这里面。

mysql.server 这个脚本使用mysqld_safe来启动mysql server.在它启动前,它会更改location到mysql的安装目录,然后运行mysqld_safe。

shell> mysql.server start

shell> mysql.server stop

Before mysql.server starts the server, it changes location to the MySQL installation directory, and then invokes mysqld_safe. To run the server as some specific user, add an appropriate user option to the [mysqld] group of the /etc/my.cnf option file, as shown later in this section. (It is possible that you must edit mysql.server if you've installed a binary distribution of MySQL in a nonstandard location. Modify it to change location into the proper directory before it runs mysqld_safe. If you do this, your modified version of mysql.server may be overwritten if you upgrade MySQL in the future, so you should make a copy of your edited version that you can reinstall.)

mysql.server stop stops the server by sending a signal to it. You can also stop the server manually by executing mysqladmin shutdown.

To start and stop MySQL automatically on your server, you must add start and stop commands to the appropriate places in your /etc/rc* files.

mysqld_multi 这个就不细谈了,以后用到再说。顾名思义就是管理多个mysql server使用的。

mysqld_safe Options

FormatDescription

--basedirPath to MySQL installation directory

--core-file-sizeSize of core file that mysqld should be able to create

--datadirPath to data directory

--defaults-extra-fileRead named option file in addition to usual option files

--defaults-fileRead only named option file

--helpDisplay help message and exit

--ledirPath to directory where server is located

--log-errorWrite error log to named file

--malloc-libAlternative malloc library to use for mysqld

--mysqldName of server program to start (in ledir directory)

--mysqld-versionSuffix for server program name

--niceUse nice program to set server scheduling priority

--no-defaultsRead no option files

--open-files-limitNumber of files that mysqld should be able to open

--pid-filePath name of server process ID file

--plugin-dirDirectory where plugins are installed

--portPort number on which to listen for TCP/IP connections

--skip-kill-mysqldDo not try to kill stray mysqld processes

--skip-syslogDo not write error messages to syslog; use error log file

--socketSocket file on which to listen for Unix socket connections

--syslogWrite error messages to syslog

--syslog-tagTag suffix for messages written to syslog

--timezoneSet TZ time zone environment variable to named value

--userRun mysqld as user having name user_name or numeric user ID user_id

参考文档:

https://dev.mysql.com/doc/refman/5.6/en/programs-server.html

LINUX重启MYSQL的命令 . 分类: Linux 2010-06-25 10:21 6367人阅读 评论(0) 收藏 举报 如何启动/停止/重启MySQL 一、启动方式 1、使用 service 启动:service mysqld start 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start 3、使用 safe_mysqld 启动:safe_mysqld& 二、停止 1、使用 service 启动:service mysqld stop 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop 3、 mysqladmin shutdown 三、重启 1、使用 service 启动:service mysqld restart 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart 提问 编辑摘要 如何启动/停止/重启MySQL 一、启动方式 1、使用 service 启动:service mysqld start 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start 3、使用 safe_mysqld 启动:safe_mysqld& 二、停止 1、使用 service 启动:service mysqld stop 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop 3、 mysqladmin shutdown 三、重启 1、使用 service 启动:service mysqld restart 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart 刚开始学 mysql时都是用redhat自带的。启动是什么 /rc.d/init.d/ start 这很简单,但是后来越学越多,系统自带的 mysql,有的是版本太低,有的是与 自己想要装的web服务需要的低版本的mysql 后来自己学着以tar的方式安装 mysql,我的mysql装在/usr/local/mysql目录下启 动碰到过很多问题。最常见的是: ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) 解决办法: [root@test mysql]# /usr/local/mysql/bin/mysqladmin -u root / > -S /var/lib/mysql/mysql.sock password 'your.passwd' 或者做个连接 ln -s /var/lib/mysql/mysql.sock /tmp 其实提示找不到 /tmp/mysql.sock有时也并不是/tmp目录下没这个文件,是启动 命令不对,我碰到过 常见的几种启动方式,自己也不是记得很清楚,如果你确定tmp下有mysql.sock这 个文件不妨试试另外的几个命令 /usr/local/mysql/bin/mysql -u root -p /usr/local/mysql/bin/mysqld --user=mysql& /usr/local/mysql/bin/mysqld --user=root& /usr/local/mysql/bin/mysqld_safe --user=root& /usr/local/mysql/bin/mysqld_safe --user=mysql& /usr/local/mysql/bin/safe_mysqld--uer=root&(注意 safe_mysqld与mysqld_safe是不同的,&表示mysql在后台运行)我的就会报错了 STOPPING server from pid file /usr/local/mysql/data/localhost.localdomain.pid 060304 11:46:21 mysqld ended 这是权限问题,我的mysql目录属于root用户,也属于root群组,改用 mysqld_safe启动就没问题了, 大家只要注意这几个 mysql,safe_mysqld,mysqld_safe,mysqld,mysqladmin.多试 几次 其实有时mysql已经正常启动了,查看mysql是否启动命令 ps -aux | grep mysqld 会看到如下类似内容 mysql 6394 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ mysql 6395 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ mysql 6396 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ root 6422 0.0 1.1 2408 732 pts/3 S 16:20 0:00 grep mysql 查看mysql是否在监听端口命令 netstat -tl | grep mysql 会看到如下类似内容 tcp 0 0 *:mysql *:* LISTEN
面向对象的设计原则(Object-Oriented Design, OOD)包括单一职责原则(Single Responsibility Principle, SRP)、开闭原则(Open-Closed Principle, OCP)、里氏替换原则(Liskov Substitution Principle, LSP)等,其单一职责原则鼓励每个类只关注一件事情。简单工厂模式就是一个体现面向对象设计的例子。 **例子 - 使用简单工厂模式(Simple Factory Pattern)进行C++的Service Oriented Architecture (SOA) 设计**: ```cpp // 定义接口或抽象基类 class Animal { public: virtual ~Animal() {} virtual std::string makeSound() const = 0; // 纯虚函数,定义声音行为 }; // 拥有具体行为的动物类 class Dog : public Animal { public: std::string makeSound() const override { return "Woof!"; } }; class Cat : public Animal { public: std::string makeSound() const override { return "Meow!"; } }; // 工厂类,使用模板实现简单工厂 template <typename T> class AnimalFactory { public: static std::unique_ptr<Animal> createAnimal() { return std::make_unique<T>(); } }; // 在客户端代码使用 int main() { auto dog = AnimalFactory<Dog>::createAnimal(); std::cout << "Dog says: " << dog->makeSound() << "\n"; auto cat = AnimalFactory<Cat>::createAnimal(); std::cout << "Cat says: " << cat->makeSound() << "\n"; return 0; } ``` 在这个例子,`Animal` 是一个抽象接口,`Dog` 和 `Cat` 实现了这个接口的行为。`AnimalFactory` 提供了一个创建特定类型动物的接口,不直接暴露创建具体类型细节给客户端,保持了灵活性。这就是SOA服务提供者和服务使用者分离的一个简单示例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值