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:
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.
tar xvf mysql-5.7.34-linux-glibc2.17-x86_64.tar.gz
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
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: # 设置新密码
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.
# 设置目录权限 sudo chown -R user:user /var/lib/mysql/ # 启动 MySQL 服务器 sudo systemctl start mysqld # 检查服务器状态 sudo systemctl status mysqld
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 | +---------------+
4. Common MySQL commands
mysql -h 主机地址 -u 用户名 -p
mysql -V
CREATE DATABASE 数据库名;
SHOW DATABASES;
DROP DATABASE 数据库名;
CREATE TABLE 表名 ( 列名1 数据类型 [约束条件], 列名2 数据类型 [约束条件], ... );
SHOW TABLES;
DROP TABLE 表名;
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!