Home > Database > Mysql Tutorial > body text

mysql installation command line

WBOY
Release: 2023-05-18 12:48:37
Original
1227 people have browsed it

1. Introduction to MySQL

MySQL is a widely used open source relational database management system. MySQL is a set of software based on client and server architecture. MySQL is a multi-user, multi-threaded SQL database server. MySQL supports the ANSI SQL standard and also supports various operating systems (Windows, Linux, UNIX, etc.).

2. MySQL installation preparation

In order to install the MySQL server on the local machine, the following preparations are required:

  1. Download the MySQL installation package: from MySQL official The website downloads the corresponding version of the installation package and supports various operating systems.
  2. Check whether the JDK environment is installed on the local machine: MySQL installer requires JDK.
  3. Check the firewall settings: Ensure that the MySQL port is not blocked by the firewall.

3. MySQL installation process

MySQL installation is divided into two modes: command line mode and graphical interface mode. This article mainly introduces the command line mode installation.

  1. Extract the installation package
tar xvf mysql-5.7.34-linux-glibc2.17-x86_64.tar.gz
Copy after login
  1. Configure MySQL

Use the root user to run the installation script in the mysql installation package and enter the interaction Configuration interface.

# 进入 MySQL 文件夹
cd ./mysql-5.7.34-linux-glibc2.17-x86_64

# 运行 MySQL 安装脚本
sudo ./bin/mysql_secure_installation
Copy after login

If you do not have root permissions, you can use sudo to run the command. The first time you run it you will be prompted to create a new password for the root user.

Enter password for user root:  # 请输入初始密码

New password:  # 设置新密码
Copy after login

After setting the password, follow the prompts to choose whether to change MySQL-related configurations, including whether to prohibit anonymous users from logging in, whether to remove the test database, etc.

  1. Start the MySQL server
# 设置目录权限
sudo chown -R user:user /var/lib/mysql/

# 启动 MySQL 服务器
sudo systemctl start mysqld

# 检查服务器状态
sudo systemctl status mysqld
Copy after login

After starting the MySQL server, you can test whether the connection is successful through the MySQL command line interface.

# 登录 MySQL 命令行界面
mysql -u root -p

# 输入密码
Enter password:

# 登录成功,输入命令查看当前用户
mysql> SELECT user();

+---------------+

| user()        |

+---------------+

| root@localhost |

+---------------+
Copy after login

4. Common MySQL commands

  1. Log in to the MySQL command line interface
mysql -h 主机地址 -u 用户名 -p
Copy after login
  1. View the MySQL version number
mysql -V
Copy after login
  1. New database
CREATE DATABASE 数据库名;
Copy after login
  1. View database
SHOW DATABASES;
Copy after login
  1. Delete database
DROP DATABASE 数据库名;
Copy after login
  1. New data table
CREATE TABLE 表名 (
  列名1 数据类型 [约束条件],
  列名2 数据类型 [约束条件],
  ...
);
Copy after login
  1. View data table
SHOW TABLES;
Copy after login
  1. Delete data table
DROP TABLE 表名;
Copy after login

The above command is just MySQL With the basic commands, MySQL can perform more operations, including data insertion, update, delete and other operations. MySQL is a powerful relational database management system, and there are many advanced uses that require further learning and mastering.

5. Summary of MySQL

MySQL is a widely used open source relational database management system that supports various operating systems and can be installed and installed through the command line or graphical interface. configuration. This article mainly introduces the command line mode installation of MySQL, including decompressing the installation package, configuring MySQL, starting MySQL, and basic MySQL commands. MySQL is a very important skill, and mastering the operation methods of MySQL can greatly improve work efficiency.

The above is the detailed content of mysql installation command line. For more information, please follow other related articles on the PHP Chinese website!

source: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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!