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)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章