ubuntu16.04 能啓動mysql服務

ubuntu16.04 後, 貌似mysqld/etc/init.d下,直接執行會報mysqld不在服務中,所以開啓mysql服務失敗。mysql

因此執行如下命令不能啓動mysql服務:
/etc/init.d/mysqld startsql

第一個念頭就是把mysql加入系統服務中唄。shell

可是,一段搗鼓以後發現。。。數據庫

ubuntu16.04後, systemctl 代替了 chkconfig。。。ubuntu

下面經過 systemctlmysqld加入服務,執行如下命令:

1.確認mysqld在/etc/init.d/目錄下,

ls /etc/init.d/mysqld (mysqld只是 support-files/mysql.server 的一個拷貝別名文件而已)ui

2.查看mysqld是否在服務中

systemctl status mysqld
證實不在服務中rest

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

3.mysqld加入服務

systemctl start mysqldcode

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

systemctl status mysqldserver

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安裝好, 那就順便來個遠程鏈接的設置吧。ci

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

相關文章
相關標籤/搜索