linux 下安装解压tar.gz 方式安装mysql5.7版

检查之前是否卸载干净mysql,参考之前的一篇博客

1.下载安装文件

http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/     mysql5.7的 各个版本,选择linux-glibc2.12-x86_64版本

[root@iZ23hdndo4vZ tmp]# wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

2.解压安装包并重命名

[root@iZ23hdndo4vZ tmp]# tar -xzvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@iZ23hdndo4vZ local]# mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql

3.在/user/local/mysql下创建data目录

[root@iZ23hdndo4vZ mysql]# mkdir data

4.创建用户mysql

# useradd -M -s /sbin/nologin  mysql

5.安装mysql服务

同时会生成初始的root密码

[root@iZ23hdndo4vZ bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
2018-09-14T01:29:19.943304Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-14T01:29:22.889460Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-14T01:29:23.344284Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-14T01:29:23.467257Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9c5a6727-b7bd-11e8-950d-00163e000746.
2018-09-14T01:29:23.478545Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-14T01:29:23.481101Z 1 [Note] A temporary password is generated for root@localhost: WtuINdwKl9/I
[root@iZ23hdndo4vZ bin]# 

6.设置开机启动

[root@iZ23hdndo4vZ mysql]# ls
bin  COPYING  data  docs  include  lib  man  README  share  support-files
[root@iZ23hdndo4vZ mysql]# cd support-files/
[root@iZ23hdndo4vZ support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@iZ23hdndo4vZ support-files]# cp mysql.server /etc/init.d/mysql
[root@iZ23hdndo4vZ support-files]# chmod +x /etc/init.d/mysql 
[root@iZ23hdndo4vZ support-files]# chkconfig --add mysql
[root@iZ23hdndo4vZ support-files]# chkconfig --list mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

7.mysql 服务开启

[root@iZ23hdndo4vZ support-files]# service mysql start
Starting MySQL                                             [  OK  ]

8.进入mysql中

密码为第四步中生成的初始化密码

[root@iZ23hdndo4vZ bin]# ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password=password("修改密码");
Query OK, 0 rows affected, 1 warning (0.00 sec)

9.给外网ip配置访问权限

mysql> grant all privileges on *.* to 'root'@'%' identified by 'hw@@2018';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

 

其他

1.mysql -u root -p  -bash:mysql:command not found 时解决方式

[root@iZ23hdndo4vZ bin]# mysql -u root -p
-bash: mysql: command not found
[root@iZ23hdndo4vZ bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@iZ23hdndo4vZ bin]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

2.修改查看mysql的最大连接数

mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> set globla max_connections=500;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'max_connections=500' at line 1
mysql> set global max_connections=500;  
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 500   |
+-----------------+-------+
1 row in set (0.00 sec)

3.查看mysql的所有远程连接情况

mysql> show processlist;
+----+------+--------------------+------+---------+------+----------+------------------+
| Id | User | Host               | db   | Command | Time | State    | Info             |
+----+------+--------------------+------+---------+------+----------+------------------+
|  6 | root | 112.17.87.192:2859 | NULL | Sleep   |  821 |          | NULL             |
|  7 | root | localhost          | NULL | Query   |    0 | starting | show processlist |
+----+------+--------------------+------+---------+------+----------+------------------+
2 rows in set (0.00 sec)

mysql> 

4.创建数据库导入sql脚本

mysql> create database ds9;
Query OK, 1 row affected (0.00 sec)

mysql> use ds9;
Database changed
mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> source /data/temp/ds9_v1.0_20180523.sql
Query OK, 0 rows affected (0.07 sec)

Query OK, 0 rows affected (0.07 sec)

Query OK, 0 rows affected (0.08 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.07 sec)

Query OK, 0 rows affected (0.07 sec)

Query OK, 0 rows affected (0.08 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.08 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.05 sec)

Query OK, 0 rows affected (0.05 sec)

 

你可能感兴趣的:(Linux)