ubuntu18.04下安裝mariaDB

在windows10中安裝了ubuntu18.04,需要安裝mariadb

更新源或者替換源

之後進行安裝

apt-get install mariadb-server

啓動和停止

sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop

在這裏插入圖片描述

設置密碼

sudo mysql_secure_installation  

在這裏插入圖片描述
上面可以配置登錄密碼,是否允許遠程訪問等。

後續的一些配置

5.使用navicate遠程連接時出現"10061error“

解決方法:

(1) 修改/etc/mysql/my.cnf文件。打開文件,找到下面內容:

 # Instead of skip-networking the default is now to listen only on
 # localhost which is more compatible and is not less secure.
 bind-address  = 127.0.0.1
 # 把上面這一行註釋掉或者把127.0.0.1換成合適的IP,建議註釋掉。

(2)但現在最新版的mariaDB 已將配置文件拆分此時my.cnf文件裏面顯示如下

!includedir /etc/mysqql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
# 這兩句話的意思是配置文件包含了上面兩個文件夾所有的文件,那麼現在一一查找bind-address  = 127.0.0.1這句話寫在哪了。
之後在/etc/mysql/mariadb.conf.d/50-server.cnf此文件下找到bind-address = 127.0.0.1這句話,註釋掉就行了。
ubuntu@DESKTOP-22ADTJ6:/etc/mysql/mariadb.conf.d$ ll
total 12
drwxr-xr-x 1 root root 4096 Apr  5 04:13 ./
drwxr-xr-x 1 root root 4096 Apr  5 13:06 ../
-rw-r--r-- 1 root root  733 Jan 30 15:25 50-client.cnf
-rw-r--r-- 1 root root  336 Jan 30 15:25 50-mysql-clients.cnf
-rw-r--r-- 1 root root 1032 Jan 30 15:25 50-mysqld_safe.cnf
-rw-r--r-- 1 root root 3719 Jan 30 15:25 50-server.cnf
ubuntu@DESKTOP-22ADTJ6:/etc/mysql/mariadb.conf.d$ pwd
/etc/mysql/mariadb.conf.d
ubuntu@DESKTOP-22ADTJ6:/etc/mysql/mariadb.conf.d$ 

編輯文件

ubuntu@DESKTOP-22ADTJ6:/etc/mysql/mariadb.conf.d$ sudo vi 50-server.cnf

#bind-address           = 127.0.0.1 				#註釋這行

修改後重啓即可

ubuntu@DESKTOP-22ADTJ6:/etc/mysql/mariadb.conf.d$ sudo /etc/init.d/mysql restart
 * Stopping MariaDB database server mysqld
   ...done.
 * Starting MariaDB database server mysqld
   ...done.
ubuntu@DESKTOP-22ADTJ6:/etc/mysql/mariadb.conf.d$ 

出現這樣的提示,應該是mysql的主機設置了訪問的主機,需要只需登錄主機,只需如下命令即可

sudo mysql -uroot -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;

記錄

ubuntu@DESKTOP-22ADTJ6:~$ sudo mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 34
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> 

在這裏插入圖片描述

出現 ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’ 可能是沒有權限,加上sudo即可

ubuntu@DESKTOP-22ADTJ6:~$ mysql -uroot -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
ubuntu@DESKTOP-22ADTJ6:~$ sudo mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章