今天在更换数据库的时候,很多命令不记得了,来做个笔记

以下内容来源于WordPress官网


You can create MySQL users and databases quickly and easily by running mysql from the shell. The syntax is shown below and the dollar sign is the command prompt:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname" IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT
Bye

The example shows:

that root is also the adminusername. It is a safer practice to choose a so-called “mortal” account as your mysql admin, so that you are not entering the command “mysql” as the root user on your system. (Any time you can avoid doing work as root you decrease your chance of being exploited.)

The name you use depends on the name you assigned as the database administrator using mysqladmin.

wordpress or blog are good values for databasename. wordpress is a good value for wordpressusername but you should realize that, since it is used here, the entire world will know it, too.

hostname will usually be localhost. If you don’t know what this value should be, check with your system administrator if you are not the admin for your WordPress host.

If you are the system admin, consider using a non-root account to administer your database.password should be a difficult-to-guess password, ideally containing a combination of upper- and lower-case letters, numbers, and symbols.

One If you need to write these values somewhere, avoid writing them in the system that contains the things protected by them. You need to remember the value used for databasename, wordpressusername, hostname, and password.

Of course, since they are already in (or will be shortly) your wp-config.php file, there is no need to put them somewhere else, too.


在MySQL8.0版本中,不再支持一条语句同时创建用户和赋予权限,需要分成两句:

1
2
3
4
mysql> CREATE USER "wordpressusername"@"hostname" IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname";
Query OK, 0 rows affected (0.00 sec)

再次更新,部分php版本无法成功连接MySQL8.0,是因为密码的原因:

1
2
3
4
mysql>CREATE USER 'username'@'host' IDENTIFIED with mysql_native_password BY 'password';
mysql>CREATE DATABASE IF NOT EXISTS databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
mysql>GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'host';
FLUSH PRIVILEGES;

本站由 @澄哥 使用 Stellar 1.27.0 主题创建。
蜀ICP备19037348号-2川公网安备51160202511796号
本页总阅读量本站总阅读量本站访客数人次
本站已安全运行:

本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。