怎么在Ubuntu18.04環(huán)境中安裝MySQL?相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站制作、網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),房縣網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:房縣等地區(qū)。房縣做網(wǎng)站價(jià)格咨詢:18980820575
安裝
mysql
sudo apt-get --purge remove mysql-server mysql-common mysql-client sudo apt-get install mysql-server mysql-common mysql-client mysqladmin -u root password your-new-password sudo /etc/init.d/mysql restart
mariadb
apt-get install mariadb-server
字符集修改utf8
如果裝的mariadb, 默認(rèn)字符集已經(jīng)是utf8了。mysql則不是
mysql> show variables like 'char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
mysql> show variables like 'collation%'; +----------------------+-------------------+ | Variable_name | Value | +----------------------+-------------------+ | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +----------------------+-------------------+
修改字符集:
sudo vim /etc/mysql/my.cnf
添加以下內(nèi)容
[mysqld] collation-server = utf8_unicode_ci init-connect='SET NAMES utf8' character-set-server = utf8
重啟:
service mysql restart
登錄權(quán)限問(wèn)題
Ubuntu18.04 安裝mysql或者mariadb之后,發(fā)現(xiàn)普通用戶和遠(yuǎn)程都沒(méi)有權(quán)限連接。
ERROR 1045: Access denied for user: 'root@localhost' (Using
password: YES)
修改了密碼也不對(duì)。然后sudo mysql -u root
即可登錄。這顯然不是我們想要的。
解決方案
刪除root,重新創(chuàng)建用戶。
首先,登錄
sudo mysql -u root
然后查看當(dāng)前用戶
SELECT User,Host FROM mysql.user; +------------------+-----------+ | User | Host | +------------------+-----------+ | admin | localhost | | debian-sys-maint | localhost | | magento_user | localhost | | mysql.sys | localhost | | root | localhost |
刪除root賬號(hào)
mysql> DROP USER 'root'@'localhost'; Query OK, 0 rows affected (0,00 sec)
重新創(chuàng)建root:
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0,00 sec)
授權(quán)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0,00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0,01 sec)
關(guān)于重置密碼
host為%
時(shí)允許遠(yuǎn)程登錄
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
or
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
or
USE mysql UPDATE user SET Password = PASSWORD('newpwd') WHERE Host = 'localhost' AND User = 'root';
允許任何地方登錄
USE mysql UPDATE user SET Password = PASSWORD('newpwd') WHERE Host = '%' AND User = 'root';
看完上述內(nèi)容,你們掌握怎么在Ubuntu18.04環(huán)境中安裝MySQL的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!