Wu Yuxiong - natural born MySQL study notes: MySQL Installation

Download MySQL for all platforms: MySQL download: https: //dev.mysql.com/downloads/mysql/ 
Note: We need to install the installation process by opening administrator rights, otherwise it will lead to the installation due to insufficient permissions.
Linux / install on UNIX MySQL 
recommended RPM package to install Mysql on Linux, MySQL AB provides the following RPM package Download: 
MySQL - MySQL server. You need this option unless you want to connect to another machine running MySQL server. 
The MySQL -client - the MySQL client program to connect and operate the server Mysql. 
MySQL -devel - Libraries and include files, if you want to compile other MySQL clients, such as Perl module, you need to install the RPM package. 
MySQL -shared - This package contains certain languages and applications need to dynamically load shared libraries (libmysqlclient.so * ), the use of MySQL. 
MySQL -bench - MySQL database server benchmark and performance testing tools. 

Before installation, we can detect whether the system comes installed MySQL: 
RPM -qa | grep MySQL 
if you have 40, it can choose to uninstall: 
RPM -e MySQL // ordinary delete mode 
RPM -e - nodeps powerful MySQL // delete mode, if you use the above command to delete, suggesting other files rely on, use the delete command can be strong
Install MySQL: 
Next we install MySQL using the yum command in Centos7 system, should be noted that CentOS 7 version of the MySQL database from the default list of programs removed, so we need to go before installing the official website to download Yum Resource Kit, Download address: https: //dev.mysql.com/downloads/repo/yum/

http://repo.mysql.com/mysql-community-release-el7-5 wget .noarch.rpm 
RPM -ivh MySQL-Community Community-Release-el7-5 .noarch.rpm 
yum Update 
yum install MySQL - Server 

permissions: 

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

initialization MySQL: 
mysqld - the initialize 
start MySQL: 
systemctl start mysqld 
view the status of running MySQL: 
systemctl status mysqld 
Note: If we are the first start mysql service, mysql server will first be configuration initialization.
Verify MySQL installed 
after a successful installation of MySQL, the table will list some basic initialization, after the server is started, you can verify that MySQL is working properly by a simple test. 

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

[root @ Host] # mysqladmin --version 
on the linux command will output the following results, the results are based on your system info: 
mysqladmin Ver 5.0.9-0, 8.23 Distrib for RedHat-linux- the GNU ON i386 
If the above command is executed not output any information to show that you Mysql is not installed successfully.
Perform simple SQL uses MySQL Client (Mysql client) command 
you can connect to the MySQL server using the mysql command in MySQL Client (Mysql client), the default login password without MySQL server is empty, so this example does not require a password . 

Command is as follows: 
[root @ Host] # mysql 
After the above command will output the mysql> prompt, indicating that you have successfully connected to the Mysql server, you can> in mysql prompt implementation of SQL command: 
mysql > SHOW DATABASES;
After installing Mysql to do 
after Mysql successful installation, the default root user password is empty, you can create the root password, use the following command: 
[root @ Host] # mysqladmin -u root password "new_password"; 
now you can the following command to connect to Mysql server: 
[root @ Host] # MySQL -u root -p 
the enter password: ******* 
Note: when you enter the password, the password is not displayed, you can correct input.
Installation on Windows MySQL 
is installed on Windows MySQL will be relatively simple, the latest version can be downloaded in MySQL: HTTPS: //dev.mysql.com/downloads/mysql/ downloaded view (more details: https: // www. runoob.com/w3cnote/windows10-mysql-installer.html installation: installing MySQL on Windows).

Click the Download button to go to the download page, click on the figure below No thanks, just start my download download immediately:

 

 

下载完后,我们将 zip 包解压到相应的目录,这里我将解压后的文件夹放在 C:\web\mysql-8.0.11 下。
接下来我们需要配置下 MySQL 的配置文件

打开刚刚解压的文件夹 C:\web\mysql-8.0.11 ,在该文件夹下创建 my.ini 配置文件,编辑 my.ini 配置以下基本信息:
[client]
# 设置mysql客户端默认字符集
default-character-set=utf8
 
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:\\web\\mysql-8.0.11
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
# datadir=C:\\web\\sqldata
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
接下来我们来启动下 MySQL 数据库:
以管理员身份打开 cmd 命令行工具,切换目录:
cd C:\web\mysql-8.0.11\bin
初始化数据库:
mysqld --initialize --console
执行完成后,会输出 root 用户的初始默认密码,如:
...
2018-04-20T02:35:05.464644Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ
...
APWCY5ws&hjQ 就是初始密码,后续登录需要用到,你也可以在登陆后修改密码。
输入以下安装命令:
mysqld install
启动输入以下命令即可:
net start mysql
注意: 在 5.7 需要初始化 data 目录:
cd C:\web\mysql-8.0.11\bin 
mysqld --initialize-insecure 
初始化后再运行 net start mysql 即可启动 mysql。
登录 MySQL
当 MySQL 服务已经运行时, 我们可以通过 MySQL 自带的客户端工具登录到 MySQL 数据库中, 首先打开命令提示符, 输入以下格式的命名:
mysql -h 主机名 -u 用户名 -p
参数说明:

-h : 指定客户端所要登录的 MySQL 主机名, 登录本机(localhost 或 127.0.0.1)该参数可以省略;
-u : 登录的用户名;
-p : 告诉服务器将会使用一个密码来登录, 如果所要登录的用户名密码为空, 可以忽略此选项。
如果我们要登录本机的 MySQL 数据库,只需要输入以下命令即可:
mysql -u root -p
按回车确认, 如果安装正确且 MySQL 正在运行, 会得到以下响应:
Enter password:
若密码存在, 输入密码登录, 不存在则直接按回车登录。登录成功后你将会看到 Welcome to the MySQL monitor... 的提示语。

然后命令提示符会一直以 mysq> 加一个闪烁的光标等待命令的输入, 输入 exit 或 quit 退出登录。

 

Guess you like

Origin www.cnblogs.com/tszr/p/12112777.html