RPI 4 OS : ubuntu 18.04 Server
安裝mariaDB
1 |
sudo apt install mariadb-server |
安裝完成後 使用mysql 都需加上sudo但會變成無密碼都可以登入,所以需改成普通可以登入方式
先使用sudo登入mysql(mariaDB)
1 |
sudo mysql -u root |
移除root
1 |
DROP USER 'root'@'localhost'; |
新增root for 全域
1 |
CREATE USER 'root'@'%' IDENTIFIED BY ''; |
授予root權限
1 |
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; |
刷新權限
1 |
FLUSH PRIVILEGES; |
確定是否有新增root用戶
1 2 3 4 5 6 7 8 9 10 11 |
SELECT User,Host FROM mysql.user; +------------------+-----------+ | User | Host | +------------------+-----------+ | root | % | | debian-sys-maint | localhost | | mysql.session | localhost | | mysql.sys | localhost | +------------------+-----------+ 4 rows in set (0.00 sec) |
測試不需要sudo即可以登入
1 |
mysql -u root -p |
Reference:
https://stackoverflow.com/questions/37239970/connect-to-mysql-server-without-sudo