On Unix (Linux), after installing MySQL according to the instructions in the manual, you must run the mysql_install_db script to create the mysql database containing the authorization
table and initial permissions. On Windows, run the Setup program in the distribution to initialize the data directory and mysql database. Assume
that the server is also running.
When you first install MySQL on your machine, the authorization table in the mysql database is initialized like this:
You can connect as root from localhost without specifying Password. The root user has all rights (including administrative rights)
and can do anything. (By the way, the MySQL superuser has the same name as the Unix superuser, they have nothing to do with each other.)
Anonymous access is granted to users who can connect locally to databases named test and any database whose name starts with test_ . Anonymous users can do
anything on the database, but have no administrative rights.
Connections to multiple servers from localhost are allowed, regardless of whether the connecting user uses a localhost hostname or a real hostname. For example:
% mysql -h localhost test
% mysql -h pit.snake.net test
The fact that you are connecting to MySQL as root without even specifying a password just means The initial installation is not secure, so as an administrator, the first thing you should do
is to set the root password, and then depending on the method you use to set the password, you can also tell the server to reload the authorization table so that it knows this change
Change. (When the server starts, it reloads the tables into memory and may not know that you have modified them.)
For MySQL 3.22 and above, you can set the password with mysqladmin:
% mysqladmin -u root password yourpassword
For any version of MySQL, you can use the mysql program and directly modify the user authorization table in the mysql database:
% mysql -u root mysql
mysql>UPDATE user SET password=PASSWORD("yourpassword") WHERE User="root";
If you have an old version of MySQL, use mysql and UPDATE.
After you set the password, check whether you need to tell the server to reload the authorization table by running the following command:
% mysqladmin -u root status
If the server still allows You connect to the server as root without specifying a password, reload the authorization table:
% mysqladmin -u root reload
After you set the root password (and reload the authorization table if necessary table), you will need to specify the
password any time you connect to the server as root