Linux commands to query mysql include: 1. The command to start mysql [mysqladmin start]; 2. The command to restart mysql [mysqladmin restart]; 3. The command to close mysql [mysqladmin shutdown].
Linux commands to query mysql are:
1,Command to start mysql: mysqladmin start
/ect/init.d/mysql start (the front is the installation path of mysql)
2,Command to restart mysql: mysqladmin restart
/ect/init.d/mysql restart (the front is the installation path of mysql)
3,Command to shut down mysql: mysqladmin shutdown
/ect/init .d/mysql shutdown (the front is the installation path of mysql)
4,Connect to mysql on this machine:
cd mysql\bin
mysql -uroot -p
Enter password
Exit mysql command: exit
5,Modify mysql password:
mysqladmin - uUsername -p old password password new password
or
mysql command line SET PASSWORD FOR root=PASSWORD("root");
##6,Add new user
grant select on database.* to username@login host identified by "password" eg: Add a user with a test password of 123, so that he can log in to any host Log in and have query, insert, modify, and delete permissions on all databases. First, connect to mysql as the root user, and then type the following commands:grant select,insert,update,delete on *.* to " Identified by "123";
7,Operations related to the mysql database
You must first log in to mysql, related operations All are performed at the mysql prompt, and each command ends with a semicolonIf you want to change the encoding format of the entire mysql:
--default-character-set=gbk# to the mysqld_safe command line##If you want to change the encoding format of a certain library: Enter the command after the mysql prompt
alter database db_name default character set gbk;
9,
Import and export of data Text data conversion Into the database The text data should conform to the format: field data are separated by tab keys, and null values are used instead. Example: 1 name duty 2006-11-23Data transfer command load data local infile "file name" into table table name;
10,
Export database and tables mysqldump --opt news > news.sql (back up all tables in the database news to the news.sql file, news.sql is a text file, the file name can be arbitrary .) mysqldump --opt news author article > author.article.sql (Back up the author table and article table in the database news to the author.article.sql file, author.article.sql is a text file, you can choose any file name.) mysqldump --databases db1 db2 > news.sql (back up database dbl and db2 to the news.sql file, news.sql is a text file, you can choose any file name .)mysqldump -h host -u user -p pass --databases dbname > file.dump
is to import the database dbname on the host with the name user and password pass into the file in file.dump mysqldump --all-databases > all-databases.sql (back up all databases to the all-databases.sql file, all-databases.sql is a text file, the file name can be arbitrary .)11,
Import data mysql 4d752f7793e3a8fd08fa8a629f2b2ca4source news.sql;( Executed under the mysql command, tables can be imported)12,Connect to MySQL
Format: mysql -h host address -u username -p user password Example 1: Connect to MYSQL on this machine. First open the DOS window, then enter the directory mysqlbin, and then type the command mysql -uroot -p. After pressing Enter, you will be prompted to enter your password. If MYSQL has just been installed, the super user root does not have a password, so directly Press Enter to enter MYSQL. The MYSQL prompt is: mysql>.Example 2: Connect to MYSQL on the remote host. Assume that the IP of the remote host is: 110.110.110.110, the user name is root, and the password is abcd123. Then type the following command:
mysql -h110.110.110.110 -uroot -pabcd123 (Note: u and root do not need to add spaces, and the same goes for others)13,
Exit the MYSQL command: exit (Enter).14,
Change password格式:mysqladmin -u用户名 -p旧密码 password 新密码
例1:给root加个密码ab12。首先在DOS下进入目录mysqlbin,然后键入以下命令:
mysqladmin -uroot -password ab12
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
例2:再将root的密码改为djg345。
mysqladmin -uroot -pab12 password djg345
15、增加新用户。(注:MySQL环境中的命令,所以后面都带一个分号作为命令结束符)
格式:grant select on 数据库.* to 用户名@登录主机 identified by \"密码\"
例1、增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MySQL,然后键入以下命令:
grant select,insert,update, delete on *.* to test1@\"%\" Identified by \"abc\";
但例1增加的用户是十分危险的,你想如某个人知道test1的密码,那么他就可以在internet上的任何一台电脑上登录你的MySQL数据库并对你的数据可以为所欲为了,解决办法见例2。
例2、增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作 (localhost指本地主机,即MySQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数据 库,只能通过MySQL主机上的web页来访问。
grant select,insert,update, delete on mydb.* to test2@localhost identified by \"abc\";
如果你不想test2有密码,可以再打一个命令将密码消掉。
grant select,insert,update,delete on mydb .* to test2@localhost identified by \"\";
更多相关免费学习推荐:mysql教程(视频)
The above is the detailed content of What are the linux commands to query mysql?. For more information, please follow other related articles on the PHP Chinese website!