ubuntu18.04安裝mysql數據庫:
sudo apt-get install mysql-server sudo apt install mysql-client sudo apt install libmysqlclient-dev
在ubuntu18.04中安裝mysql時,沒有提示設置密碼,但是登陸的時候又需要密碼才能登陸
在網上找了很久,找到了一篇文章:https://blog.csdn.net/qq_38737992/article/details/81090373
首先:
sudo cat /etc/mysql/debian.cnf
可以看到上面紅色箭頭指出來的密碼
然后登陸:
mysql -u debian-sys-maint -p
登陸輸入的密碼就是上面的密碼
然后修改密碼:
use mysql; update mysql.user set authentication_string=password('root') where user='root' and Host ='localhost'; update user set plugin="mysql_native_password"; flush privileges; quit;
最后重啟數據庫服務:
sudo service mysql restart
此時,就可以使用自己的密碼登陸數據庫了。
配置數據庫遠程訪問
打開文件/etc/mysql/mysql.conf.d/mysqld.cnf
將bind-address = 127.0.0.1注釋掉
然后保存文件,重新進入數據庫:mysql -u root -p
然后執行如下指令:
grant all on *.* to root@'%' identified by 'your_password' with grant option; flush privileges; 注意:上面的your_password是你自己的數據庫的連接密碼
然后重啟數據庫:
service mysql restart