Home Database Mysql Tutorial Some basic usage of mysql under linux

Some basic usage of mysql under linux

Dec 16, 2016 am 11:23 AM

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 < /home/beinan/linuxsir031130.sql
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 of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Get the gate.io installation package for free Get the gate.io installation package for free Feb 21, 2025 pm 08:21 PM

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi Exchange Download Official Portal Ouyi Exchange Download Official Portal Feb 21, 2025 pm 07:51 PM

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

gate.io official website registration installation package link gate.io official website registration installation package link Feb 21, 2025 pm 08:15 PM

Gate.io is a highly acclaimed cryptocurrency trading platform known for its extensive token selection, low transaction fees and a user-friendly interface. With its advanced security features and excellent customer service, Gate.io provides traders with a reliable and convenient cryptocurrency trading environment. If you want to join Gate.io, please click the link provided to download the official registration installation package to start your cryptocurrency trading journey.

How to Install phpMyAdmin with Nginx on Ubuntu? How to Install phpMyAdmin with Nginx on Ubuntu? Feb 07, 2025 am 11:12 AM

This tutorial guides you through installing and configuring Nginx and phpMyAdmin on an Ubuntu system, potentially alongside an existing Apache server. We'll cover setting up Nginx, resolving potential port conflicts with Apache, installing MariaDB (

See all articles