---------- 20190118 1. 確認 使用者帳號可遠端連線. 在本機執行: GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'IP' IDENTIFIED BY 'PASSWORD'; IP 可指定 或 以'%表示開放全部IP 例如 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES; WINDOWS: 可在 C:\Program Files\MySQL\MySQL Server 5.X\bin 目錄下執行 mysql -u root -p MySQL 8.0 從 MySQL 8版本開始, GRANT 指令不再隱含新增使用者帳號. 必須改以2個指令完成: create user 'root'@'%' identified by 'Passmysql1!'; grant all privileges on *.* to 'root'@'%' with grant option; flush privileges; Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT command. Use CREATE USER instead, followed by the GRANT statement: mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'root'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; This worked for me mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; 2. 檢查 my.cnf bind-address 設定 將這一列: bind-address = 127.0.0.1 改成: #bind-address = 127.0.0.1 或 bind-address=* my.cnf檔案位置 linux: /etc/mysql/my.cnf 或 /etc/mysql/mysql.conf.d/mysqld.cnf windows C:\Program Files\MySQL\MySQL Server 5.5\my.ini MySQL8: For MySQL 8 open the mysqld.cnf file sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf And modify or add the bind-address option: [mysqld] bind-address = 0.0.0.0 Restart the mysql server sudo service mysql restart grant all privileges on 'bbs' to 'userone'@'localhost' IDENTIFIED BY PASSWORD 'user2012'; It shows ERROR 1064 (42000): You have an error in your SQL syntax; check the manual I want to add a user userone and grant all privileges to the database bbs. How to correct it? You need to include an indicator for the tables in the database you want to grant the privilege. Change the query: grant all privileges on bbs.* to 'userone'@'localhost' IDENTIFIED BY PASSWORD 'user2012'; to grant it for all the tables in the 'bbs' database. ---------- 20190114 That is allowed by default on MySQL. What is disabled by default is remote root access. If you want to enable that, run this SQL command locally: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES; And then find the following line and comment it out in your my.cnf file, which usually lives on /etc/mysql/my.cnf on Unix/OSX systems. In some cases the location for the file is /etc/mysql/mysql.conf.d/mysqld.cnf). If it's a Windows system, you can find it in the MySQL installation directory, usually something like C:\Program Files\MySQL\MySQL Server 5.5\ and the filename will be my.ini. Change line bind-address = 127.0.0.1 to #bind-address = 127.0.0.1 And restart the MySQL server (Unix/OSX, and Windows) for the changes to take effect. ---------- 20190109 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) For MySQL < 5.7: The default root password is blank (i.e. empty string) not root. So you can just login as: mysql -u root You should obviously change your root password after installation mysqladmin -u root password [newpassword] In most cases you should also set up individual user accounts before working extensively with the DB as well. ---------- At the initial start up of the server the following happens, given that the data directory of the server is empty: 1. The server is initialized. 2. SSL certificate and key files are generated in the data directory. 3. The validate_password plugin is installed and enabled. 3. The superuser account 'root'@'localhost' is created. The password for the superuser is set and stored in the error log file. To reveal it, use the following command: shell> sudo grep 'temporary password' /var/log/mysqld.log Change the root password as soon as possible by logging in with the generated temporary password and set a custom password for the superuser account: shell> mysql -uroot -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!';