Mysql

ubuntu16.04 能启动mysql服务

Posted by Liangjf on April 9, 2019

ubuntu16.04 能启动mysql服务

ubuntu16.04 后, 貌似mysqld/etc/init.d下,直接执行会报mysqld不在服务中,因此开启mysql服务失败。

所以执行以下命令不能启动mysql服务: /etc/init.d/mysqld start

第一个念头就是把mysql加入系统服务中呗。

但是,一段捣鼓之后发现。。。

ubuntu16.04后, systemctl 代替了 chkconfig。。。

下面通过 systemctlmysqld加入服务,执行以下命令:

1.确认mysqld在/etc/init.d/目录下,

ls /etc/init.d/mysqld (mysqld只是 support-files/mysql.server 的一个拷贝别名文件而已)

2.查看mysqld是否在服务中

systemctl status mysqld 证明不在服务中

● mysqld.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

3.mysqld加入服务

systemctl start mysqld

4.再次查看mysqld是否在服务中

systemctl status mysqld

   mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/init.d/mysqld; bad; vendor preset: enabled)
   Active: active (running) since Tue 2019-03-19 09:32:40 PDT; 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 11364 ExecStart=/etc/init.d/mysqld start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mysqld.service
           ├─11392 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/ubuntu.pid
           └─12330 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-erro

远程连接

mysql安装好, 那就顺便来个远程连接的设置吧。

1.选中mysql数据库:

mysql>use mysql;

2.查看用户和host:

mysql>select host,user,password from user;

+-----------+------+----------+
| host      | user | password |
+-----------+------+----------+
| localhost | root |          |
| ubuntu    | root |          |
| 127.0.0.1 | root |          |
| ::1       | root |          |
| localhost |      |          |
| ubuntu    |      |          |
+-----------+------+----------+

3.更新用户和host信息:

mysql> update user set host='%' where user='root';

Query OK, 0 rows affected (0.00 sec)

4.确认用户和host信息:

mysql> select user, host from user;

+------+-----------+
| user | host      |
+------+-----------+
| root | %         |
| root | 127.0.0.1 |
| root | ::1       |
|      | localhost |
|      | ubuntu    |
| root | ubuntu    |
+------+-----------+
6 rows in set (0.00 sec)

5.退出:

mysql> quit

6.重启mysql:

shell>/etc/init.d/mysqld restart

7.远程连接mysql:

我用的是MySQL Workbench