Create a mysql user and authorize: Format: grant permission on database name.table name to user@login host identified by "user password"; grant[英][grɑ:nt] admit; agree; allow; grant; Example 1: Allow the mk user to log in from localhost mysql> grant all on book.* to mk1@localhost identified by "123456"; #Allow access to all tables under the book database. Only book tables can be accessed, and users on the same server Allow the mk2 user to connect to the mysql server from any remote host: mysql> grant all privileges on *.* to mk2@'%' identified by '123456' with grant option; # with grant option means that the mk2 user can delegate his own permissions to the newly created user. In addition, you can add or not add privileges. % refers to any remote host, excluding local addresses and localhost Flush privileges; Refresh the database test: [root@xuegod64 ~]# mysql -u mk2 -h 192.168.1.63 -p123456 mysql> #Login is normal but: [root@xuegod63 ~]# mysql -u mk2 -h 192.168.1.63 -p123456 #Cannot log in Solution: mysql> grant all privileges on *.* to 'mk2'@'192.168.1.63' identified by '123456' with grant option; [root@xuegod63 ~]# mysql -u mk2 -p123456 #Cannot log in Solution: mysql> grant all privileges on *.* to 'mk2'@'localhost' identified by '123456' with grant option; To summarize: % refers to any remote host, excluding the local address and localhost. In addition, the grant takes effect immediately. No need to execute: mysql> flush privileges; #Manual update command Only when you manually modify the MySQL related fields, you need to execute mysql> flush privileges; Authorize only some permissions: mysql> grant select,insert,update,delete,create,drop on aa.* to 'custom'@'localhost' identified by '123456'; Method 2: Directly modify the permission file in the table: mysql> use mysql; mysql> insert into user (Host,User,Password) values('localhost','grace','123456'); mysql> select Host,User,Password from user where User="grace"; +-----------+-------+----------+ | Host | User | Password | +-----------+-------+----------+ | localhost | grace | 123456 | +-----------+-------+----------+ You can see that the password is stored in plain text and is now stored in encrypted form: mysql> insert into user (Host,User,Password) values('localhost','grace1',password("123456")); Query OK, 1 row affected, 3 warnings (0.00 sec) mysql> select Host,User,Password from user where User="grace1"; +-----------+--------+-------------------------------------------+ | Host | User | Password | +-----------+--------+-------------------------------------------+ | localhost | grace1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +-----------+--------+-------------------------------------------+ 1 row in set (0.01 sec) mysql> flush privileges; #Refresh the privilege table to make the configuration file effective Or restart the mysql database [root@xuegod63 ~]# service mysqld restart test: [root@xuegod63 ~]# mysql -u grace -p123456 #Login failed ERROR 1045 (28000): Access denied for user 'grace'@'localhost' (using password: YES) [root@xuegod63 ~]# mysql -u grace1 -p123456 #Login successful To change your account password: Method 1: Use mysqladmin to change the password Example 1: When root has no password: [root@xuegod63 mysql]# mysqladmin -u root -h 192.168.1.63 password '123' [root@xuegod63 mysql]# mysql -u root -h 192.168.1.63 -p123 Example 2: When root already has a password: [root@xuegod63 ~]# mysqladmin -u root password '123456' -p123 Method 2: Use set password to change the password: mysql> SET PASSWORD FOR 'grace1'@'localhost' = PASSWORD('123456'); #Note, your MySQL database already has a record: grace1'@'localhost mysql> set password = password('1234567'); mysql> FLUSH PRIVILEGES; Reset root password: [root@xuegod63 mysql]# /etc/init.d/mysqld stop [root@xuegod63 mysql]# mysqld_safe --skip-grant-tables --skip-networking Only valid in MySQL 5.1 Open a new terminal: You can log in directly, and then use update to change the password [root@xuegod63 aa]# mysql #Execute mysql> update mysql.user set password=password('123456') where host='localhost' and user='root'; [root@xuegod63 aa]# /etc/init.d/mysqld restart Stopping mysqld: [ OK ] The above is the method of changing the password and remotely logging into the MySQL database in MySQL 5.1 version introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: A record of the pitfalls of the WeChat applet component life cycle
>>: Some functions of using tcpdump to capture packets in the Linux command line
1. Vector Map Vector graphics use straight lines ...
What is HTTP? When we want to browse a website, w...
Red and pink, and their hexadecimal codes. #99003...
Preface Project release always requires packaging...
This article example shares the specific code of ...
Preparation 1. Start the virtual machine 2. git t...
Table of contents Typical Cases Appendix: Common ...
Occasionally you'll see characters such as &#...
Preface My needs are syntax highlighting, functio...
Table of contents style scoped style module State...
The operating environment of this tutorial: Windo...
The legend component is a commonly used component...
Rendering Define the skeleton, write HTML and CSS...
The effect of completing a menu bar through displ...
CPU Load and CPU Utilization Both of these can re...