Why MySQL does not have a MySQL database after installation

Source: Internet
Author: User
Tags mysql host
There is no MySQL database after MySQL is installed. After mysql is installed, it is found that there are only two databases: mysqlgt; showdatabases;

There is no MySQL database after MySQL is installed. After mysql is installed, it is found that there are only two databases: mysqlgt; show databases;

After mysql is installed, login finds that there are only two databases:Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Test |
+ -------------------- +
,Mysql> use mysql
ERROR 1044 (42000): Access denied for user ''@ 'localhost' to database 'mysql'

Access is denied because the/var/lib/mysql directory is not deleted when the database is deleted (rpm-e mysql, and then reinstall it.

By the way, remember some common commands:

1. Connect to MYSQL.
Format: mysql-h host address-u user name-p User Password

1. Connect to MYSQL on the local machine.
# Mysql-u root-p
After you press enter, you will be prompted to enter the password. Note that there can be space or no space before the user name, but there must be no space before the password; otherwise, you will be asked to re-enter the password.
If you have just installed MYSQL, the Super User root has no password, so press enter to enter MYSQL. The MYSQL prompt is: mysql>

2. Connect to MYSQL on the remote host. Assume that the IP address of the remote host is 192.168.2.2, the user name is root, and the password is 123456. Enter the following command:
# Mysql-h192.168.2.2-uroot-p123456

3. Exit MYSQL command:
# Exit (Press ENTER)

2. Change the password.
Format: mysqladmin-u username-p old password New password

1. Add a 123456 password to the root user. Type the following command:
# Mysqladmin-u root-password 123456

2. Change the password of root to 56789.
# Mysqladmin-u root-p123456 password 56789

3. Add new users.
Format: grant select on database. * to username @ login host identified by "password"

1. Add a user named "test1" with the password "abc" so that he can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MYSQL, and then type the following command:
Mysql> grant select, insert, update, delete on *. * to test1 @ "%" Identified by "abc ";
Mysql> flush privileges;

2. Add a user named "test2" with the password "abc" so that the user can only log on to localhost and query, insert, modify, and delete the database mydb (localhost refers to the local host, that is, the host where the MYSQL database is located. In this way, the user knows the password of test2, and cannot directly access the database from the internet, but can only access the database through the web page on the MYSQL host.
Mysql> grant select, insert, update, delete on mydb. * to test2 @ localhost identified by "abc ";
Mysql> flush privileges;

If you do not want test2 to have a password, you can run another command to remove the password.
Mysql> grant select, insert, update, delete on mydb. * to test2 @ localhost identified by "";
Mysql> flush privileges;

Operation Skills
1. If you forget the extra points after you press Enter when making the command, you don't have to repeat the command. You just need to press a semicolon to press Enter. That is to say, you can divide a complete command into several lines, and then use a semicolon as the end sign to complete the operation.
2. You can use the cursor to bring up or down the previous commands.

Query, create, delete, and update commands

1. display the list of databases on the current database server:
Mysql> show databases;
Note: the mysql database contains the MYSQL system information. We change the password and add new users to use this database for operations.

2. display data tables in the database:
Mysql> use Database Name;
Mysql> show tables;

3. display the data table structure:
Mysql> describe table name;

4. Create a database:
Mysql> create database name;

5. Create a data table:
Mysql> use Database Name;
Mysql> create table Name (field name varchar (20), field name char (1 ));

6. delete a database:
Mysql> drop database name;

7. delete a data table:
Mysql> drop table name;

8. Clear records in the table:
Mysql> delete from table name;

9. display the records in the table:
Mysql> select * from table name;

10. insert records into the table:
Mysql> insert into table name values ("123", "B ");

11. Update table data:
Mysql> update table name set field name 1 = 'A', field name 2 = 'B' where field name 3 = 'C ';

12. load data into a data table in text mode:
Mysql> load data local infile "/root/mysql.txt" into table name;

13. Import the. SQL FILE command:
Mysql> use Database Name;
Mysql> source/root/mysql. SQL;

14. Change the root password on the command line:
Mysql> update mysql. user set password = PASSWORD ('new password') where user = 'root ';
Mysql> flush privileges;

15. display the Database Name of use:
Mysql> select database ();

16. display the current user:
Mysql> select user ();

Back up database

1. Export the entire database. The exported files are stored in the current operation directory by default.
# Mysqldump-u username-p Database Name> exported file name
# Mysqldump-u user_name-p123456 database_name> outfile_name. SQL

2. Export a table
# Mysqldump-u username-p database name Table Name> exported file name
# Mysqldump-u user_name-p database_name table_name> outfile_name. SQL

3. Export a database structure
# Mysqldump-u user_name-p-d-add-drop-table database_name> outfile_name. SQL
-D no data-add-drop-table add a drop table before each create statement

4. Export with language Parameters
# Mysqldump-uroot-p-default-character-set = latin1-set-charset = gbk-skip-opt database_name> outfile_name. SQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.