The default root user of mysql has no password, enter mysql –u root to enter mysql
1. Initialize the root password
enter mysql database
MySQL 5.7.6 and latest:
mysql> update user set authentication_string=PASSWORD('newpass') where User='root'; //make changes take effect mysql>FLUSH PRIVILEGES //Exit MySQL server mysql>EXIT
MySQL 5.7.5 or earlier:
mysql>update user set password=PASSWORD('newpass') where User='root';
You must reset your password using ALTER USER statement before executing this statement.
SET PASSWORD = PASSWORD('new password');
2. To allow mysql remote access, you can use the following three methods:
a. Change the table
mysql -u root –p mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>select host, user from user;
b. Authorization.
For example, you want root to connect to mysql server from any host using 123456.
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
If you want to allow user jack to connect to mysql server from host with ip 10.10.50.127 and use 654321 as password
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION; mysql>FLUSH RIVILEGES
c: On the machine where mysql is installed run:
//Enter MySQL server d:\mysql\bin\>mysql -h localhost -u root //Give any host permission to access the data mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //make changes take effect mysql>FLUSH PRIVILEGES //Exit MySQL server mysql>EXIT