MySQL latest ma...login
MySQL latest manual tutorial
author:php.cn  update time:2022-04-15 14:04:12

MySQL installation


MySQL installation

Mysql download address for all platforms is: MySQL download. Select the MySQL Community Server version and corresponding platform you need.

Related tutorial recommendations:


##Installation on Linux/UNIX MySQL

It is recommended to use the RPM package to install Mysql on the Linux platform. MySQL AB provides the download address of the following RPM package:

  • MySQL - MySQL server. You need this option unless you only want to connect to a MySQL server running on another machine.

  • MySQL-client - MySQL client program, used to connect and operate the Mysql server.

  • MySQL-devel - library and include files. If you want to compile other MySQL clients, such as Perl modules, you need to install this RPM package.

  • MySQL-shared - This package contains shared libraries (libmysqlclient.so*) that some languages ​​and applications need to load dynamically, using MySQL.

  • MySQL-bench - Benchmark and performance testing tool for MySQL database servers.

Before installation, we can check whether the system comes with MySQL installed:

rpm -qa | grep mysql

If your system has it installed, you can choose to uninstall it:

rpm -e mysql  // 普通删除模式
rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,
则用该命令可以对其进行强力删除

Install MySQL:

Next we use the yum command to install MySQL under the Centos7 system. It should be noted that the MySQL database in the CentOS 7 version has been changed from the default is removed from the program list, so before installation we need to go to the official website to download the Yum resource package. The download address is: https://dev.mysql.com/downloads/repo/yum/

1548661715958137.png

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpmrpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server

Permission settings:

chown mysql:mysql -R /var/lib/mysql

Initialize MySQL:

mysqld --initialize

Start MySQL:

systemctl start mysqld

View MySQL running status:

systemctl status mysqld

Note: If we start the mysql service for the first time, the mysql server will first perform initial configuration.

In addition, you can also use MariaDB instead. The MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community and is licensed under the GPL. One of the reasons for developing this branch is that after Oracle acquired MySQL, there was a potential risk of MySQL being closed source, so the community adopted a branch approach to avoid this risk.

MariaDB aims to be fully compatible with MySQL, including API and command line, making it an easy replacement for MySQL.

yum install mariadb-server mariadb

The relevant commands for the mariadb database are:

systemctl start mariadb  #启动MariaDB
systemctl stop mariadb  #停止MariaDB
systemctl restart mariadb  #重启MariaDB
systemctl enable mariadb  #设置开机启动

Verify MySQL installation

After successfully installing MySQL, some basics The table will be initialized. After the server starts, you can verify that MySQL is working properly through a simple test.

Use the mysqladmin tool to get the server status:

Use the mysqladmin command to check the server version. On Linux, the binary file is located in the /usr/bin directory. On Windows, the binary file is located in C :\mysql\bin .

[root@host]# mysqladmin --version

This command on Linux will output the following results, which are based on your system information:

mysqladmin  Ver 8.23 Distrib 5.0.9-0, for redhat-linux-gnu on i386

If no information is entered after the above command is executed, it means that your Mysql was not installed successfully.

Use MySQL Client (Mysql client) to execute simple SQL commands

You can use MySQL Client (Mysql client) to use mysql commands Connect to the MySQL server. By default, the login password of the MySQL server is empty, so you do not need to enter a password in this example.

The command is as follows:

[root@host]# mysql

After the above command is executed, the mysql> prompt will be output, which means that you have successfully connected to the Mysql server. You can execute SQL commands at the mysql> prompt:

mysql> SHOW DATABASES;+----------+| Database |+----------+| mysql    || test     |+----------+2 rows in set (0.13 sec)

What you need to do after Mysql installation

After Mysql is successfully installed, the default root user password is empty. You can use the following command to create it Password of the root user:

[root@host]# mysqladmin -u root password "new_password";

Now you can connect to the Mysql server through the following command:

[root@host]# mysql -u root -pEnter password:*******

Note: When entering the password, the password will not be displayed. You can enter it correctly. .

Installing MySQL on Windows

Installing MySQL on Windows is relatively simple, the link is: https://cdn.mysql. com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip Download the zip package.

The latest version can be viewed in MySQL Download.

330405-20160709174318905-664331194.png

1548662169678607.png

Click the Download button to enter the download page, click No thanks, just start my download. in the picture below to download immediately:

1548662129812961.png

After downloading, we will unzip the zip package to the corresponding directory. Here I will put the unzipped folder under C:\web\mysql-8.0.11.

Next we need to configure the MySQL configuration file

Open the folder you just decompressed C:\web\mysql-8.0.11 and create the my.ini configuration file in this folder , edit my.ini to configure the following basic information:

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 [mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:\web\mysql-8.0.11
# 设置mysql数据库的数据的存放目录,MySQL8+不需要以下配置,系统自己生成即可,否则有可能报错
#datadir=C:\web\sqldata
#允许最大连接数
max_connections=20
#服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

Next we start the MySQL database:

Open the cmd command line tool as an administrator and switch directories:

cd C:\web\mysql-8.0.11\bin

Initialize the database:

mysqld --initialize --console

After the execution is completed, the initial default password of the root user will be output, such as:

...
2018-04-20T02:35:05.464644Z 5 [Note] [MY-010454] 
[Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ
...

APWCY5ws&hjQ is the initial password, which will be used for subsequent logins. You can also log in Then change the password.

Enter the following installation command:

mysqld install

Enter the following command to start:

net start mysql

Note: In 5.7, the data directory needs to be initialized:

cd C:\web\mysql-8.0.11\bin mysqld --initialize-insecure

After initialization Then run net start mysql to start mysql.

Login to MySQL

When the MySQL service is already running, we can log in to the MySQL database through the client tool that comes with MySQL. First Open the command prompt and enter the name in the following format:

mysql -h 主机名 -u 用户名 -p

Parameter description:

-h: Specify the MySQL host name where the client wants to log in, log in to this machine ( localhost or 127.0.0. 1) This parameter can be omitted;

-u: Login user name;

-p: Tell the server that a password will be used to log in. If the user to log in If the username and password are empty, you can ignore this option.

If we want to log in to the local MySQL database, we only need to enter the following command:

mysql -u root -p

Press Enter to confirm. If the installation is correct and MySQL is running, you will get the following response:

Enter password:

If the password exists, enter the password to log in. If it does not exist, just press Enter to log in. After successfully logging in, you will see the Welcome to the MySQL monitor... prompt.

Then the command prompt will always be mysq> with a blinking cursor waiting for command input. Enter exit or quit to log out.