search
HomeDatabaseMysql TutorialSome basic usage of mysql under linux

1] How to create an administrative user for the MySQLd database?

After the database is installed, we should create an administrative account for the mysql database. To set the root user as administrator, we should run the following command;

[root@linuxsir01 root]# /opt/mysql/bin/mysqladmin -u root passWord 123456
[root@linuxsir01 root]#

via the above command, we can know that the administrator of the mysql database is root and the password is 123456.

2] How to enter the mysql database? Take the mysql database administrator root with the password 123456 as an example;

[root@linuxsir01 root]#/opt/mysql/bin/mysql -uroot -p123456

After outputting the above command, the following prompt appears;

Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 6 to server version: 3.23.58

Type 'help;' or 'h' for help. Type 'c' to clear the buffer .

mysql>

Note: When operating these commands, the mysqld server should be opened. These novice brothers have known it for a long time:)


3] How to operate commands in the database, I think this is all in the mysql manual. I will mainly talk about a few things to pay attention to. In fact, I can't understand a few commands. If you want to learn it yourself, it is not difficult; if you have operated mysql in windows, it is actually the same here. Mysql is a cross-platform database, and its usage is the same.

In the mysql database, every command ends with a ; sign. Some novice brothers may have forgotten to enter a ; sign, and the result cannot be exited. :):)

1] Check what databases are available in mysql?

Code:

mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)

mysql>

After mysql is installed and the administrator is set up, when entering the system for the first time, we use show databases; Use the command to view the list of databases and find that there are two databases, mysql and test. These are self-built by the system and are for everyone to practice.

4] How to create and delete a database?

For example, if I want to create a database named linux, I should run the following command

mysql> create database [database name];

So we should run the following command to create a database named linux

mysql> create database linux;
Query OK, 1 row affected (0.00 sec)

Has it been built? ? It must have been built, because everything is OK :)

Check if there is a Linux database?

Code:

mysql> show databases;
+----------+
| Database |
+----------+
| linux |
| mysql |
| test |
+----------+
3 rows in set (0.00 sec)

mysql>

So how do we delete a database? ?
mysql> drop database [database name];

For example, if we want to delete the linux database we just created, we should use the following command;
mysql> drop database linux;
Query OK, 0 rows affected (0.00 sec)

Yes Hasn't it been deleted? ?

Code:

mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)

mysql>


5] There are many questions about how to operate a database. It is recommended to read the mysql manual. There's so much in there. If you operate a database, you must first specify a database as the current database. You should use the use command

mysql> use [database];

For example, if I want to specify the linux database as the current database, it should be

mysql> use linux;
Database changed
mysql>



6] How to back up the database? ?

For example, if we want to back up a database named linux that already exists in mysql, we need to use the command mysqldump

The command format is as follows:

[root@linuxsir01 root]# /opt/mysql/bin/mysqldump -uroot -p linux > /root/linux.sql
Enter password: Enter the password of the database here

Through the above command, we need to understand two things. First, the database must be backed up as a database administrator; secondly: the backup destination It is /root, and the backup file name is linux.sql. In fact, the location and file name of the backup are determined according to your own situation. You can choose the file name yourself and arrange the path yourself;

For example, I want to back up the Linux database to /home/beinan. The file name of the database is linuxsir031130.sql, so I should enter the following command.
[root@linuxsir01 root]#/opt/mysql/bin/mysqldump -uroot -p linux > /home/beinan/linuxsir031130.sql
Enter password: Enter the database password of the database administrator root here

This way we get to The backup file linuxsir031130.sql of the database named linux in mysql can be found in the /home/beinan directory

To sum up, we must learn to be flexible when studying. :):)

5] How to import the backed up database into the database?

First we still need to operate the above processes, such as adding a database administrator (if you have not added a mysql database administrator), creating a database, etc.

For example, if we want to import the backup of linuxsir031130.sql in the directory /home/beinan into a database named linux, we should do the following;

[root@linuxsir01 root]# /opt/mysql/bin/mysql -uroot -p linux Enter password: Enter the password here

If the machine is good and the database is small, it will only take a few minutes.

6] Some other commonly used mysql commands;

View status
mysql> show status;

View process

Code:

mysql> show PRocesslist;
+----+----- -+-----------+------+---------+------+-------+---- ---------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------+--- --------+------+---------+------+-------+--------- ---------+
| 16 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+----+------+------- ----+------+---------+------+-------+------------- -----+
1 row in set (0.00 sec)

mysql>

To view the table, you should first specify a database as the current database; for example, a database named linux;

mysql>use linux;
mysql> ; show tables;
Empty set (0.00 sec)

mysql>


7] A little supplement to the common commands of mysql database;


Several commonly used mysql related management commands

mysql command: basic text, Display and use the mysql database. The usage has been briefly mentioned before; such as login, etc.

mysqladmin command, a command used to create and maintain mysql database, has been briefly mentioned before;

isamchk is used to repair, check and optimize database files with .ism suffix;

mysqldump is used to back up the database, as mentioned earlier It has been briefly explained;


myisamchk is used to repair the database file with the .myi suffix;

For example, if we want to check whether there is a problem with the .myi database table of the database named linux, we should use the following command;

To use mysqld Server stop
[root@linuxsir01 root]# /opt/mysql/share/mysql.server stop

Then execute
[root@linuxsir01 root]# /opt/mysql/bin/myisamchk /opt/mysql/var/linux /*.MYI

The above command means to check all .myi files. The database directory is in the /opt/mysql/var/linux/ directory

If there is a problem, you should use the -r parameter to fix it
[root @linuxsir01 root]# /opt/mysql/bin/myisamchk -r /opt/mysql/var/linux/*.MYI

6]mysqlshow command: Display the database and table selected by the user
[root@linuxsir01 root]# / opt/mysql/bin/mysqlshow -uroot -p [database name]

For example, if I want to view the database named linux; it should be:

[root@linuxsir01 root]# /opt/mysql/bin/mysqlshow -uroot - p linux

The above is the basic usage of mysql under Linux. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you create and manage user accounts in MySQL?How do you create and manage user accounts in MySQL?Apr 22, 2025 pm 06:05 PM

The steps to create and manage user accounts in MySQL are as follows: 1. Create a user: Use CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password'; 2. Assign permissions: Use GRANTSELECT, INSERT, UPDATEONmydatabase.TO'newuser'@'localhost'; 3. Fix permission error: Use REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost'; then reassign permissions; 4. Optimization permissions: Use SHOWGRA

How does MySQL differ from Oracle?How does MySQL differ from Oracle?Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

What are the disadvantages of using MySQL compared to other relational databases?What are the disadvantages of using MySQL compared to other relational databases?Apr 22, 2025 pm 05:49 PM

The disadvantages of MySQL compared to other relational databases include: 1. Performance issues: You may encounter bottlenecks when processing large-scale data, and PostgreSQL performs better in complex queries and big data processing. 2. Scalability: The horizontal scaling ability is not as good as Google Spanner and Amazon Aurora. 3. Functional limitations: Not as good as PostgreSQL and Oracle in advanced functions, some functions require more custom code and maintenance.

How do you perform a JOIN operation in MySQL?How do you perform a JOIN operation in MySQL?Apr 22, 2025 pm 05:41 PM

MySQL supports four JOIN types: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN is used to match rows in two tables and return results that meet the criteria. 2.LEFTJOIN returns all rows in the left table, even if the right table does not match. 3. RIGHTJOIN is opposite to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet the conditions.

How does MySQL's performance compare to other RDBMS under high load?How does MySQL's performance compare to other RDBMS under high load?Apr 22, 2025 pm 05:37 PM

MySQL's performance under high load has its advantages and disadvantages compared with other RDBMSs. 1) MySQL performs well under high loads through the InnoDB engine and optimization strategies such as indexing, query cache and partition tables. 2) PostgreSQL provides efficient concurrent read and write through the MVCC mechanism, while Oracle and Microsoft SQLServer improve performance through their respective optimization strategies. With reasonable configuration and optimization, MySQL can perform well in high load environments.

Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor