Mysql 5.7.21 install for Linux

chenoracle發表於2018-06-02
Mysql 5.7.21 install for Linux


一:下載
二:安裝前準備
三:安裝

一:下載
1 下載地址
dev.mysql.com/downloads/mysql
2 安裝包
mysql-5.7.21-linux-glibc2.12-x86_64.tar


二:安裝前準備
1 解除安裝系統預設安裝的mysql(謹慎操作)
[root@rac1 bin]# rpm -qa|grep mysql
[root@rac1 bin]# rpm -e mysql-connector-odbc-5.1.5r1144-7.el6.x86_64 --nodeps
[root@rac1 bin]# rpm -e mysql-devel-5.1.66-2.el6_3.x86_64 --nodeps
[root@rac1 bin]# rpm -e mysql-5.1.66-2.el6_3.x86_64 --nodeps
[root@rac1 bin]# rpm -e mysql-libs-5.1.66-2.el6_3.x86_64 --nodeps
[root@rac1 bin]# rpm -e mysql-server-5.1.66-2.el6_3.x86_64 --nodeps
......

2 建立mysql使用者和組
[root@rac1 bin]# groupadd mysql
[root@rac1 bin]# useradd -g mysql mysql
[root@rac1 bin]# id mysql
uid=493(mysql) gid=5006(mysql) groups=5006(mysql)
[root@rac1 bin]# passwd mysql

三:安裝
1 解壓
[root@rac1 mysql]# cd /package/mysql/
[root@rac1 mysql]# ll -rth
total 641M
-rw-r--r-- 1 root root 641M Jun  4 10:22 mysql-5.7.21-linux-glibc2.12-x86_64.tar

[root@rac1 mysql]# tar -xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar 
mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mysql-test-5.7.21-linux-glibc2.12-x86_64.tar.gz

[root@rac1 mysql]# ll -rth
total 1.3G
-rw-r--r-- 1 7161 31415  28M Dec 28 12:18 mysql-test-5.7.21-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 7161 31415 613M Dec 28 12:20 mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 root root  641M Jun  4 10:22 mysql-5.7.21-linux-glibc2.12-x86_64.tar

[root@rac1 mysql]# tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

[root@rac1 mysql]# du -sh mysql-5.7.21-linux-glibc2.12-x86_64 
2.5G mysql-5.7.21-linux-glibc2.12-x86_64

[root@rac1 mysql]# cp -r mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
[root@rac2 etc]# chown mysql.mysql /usr/local/mysql -R

2 建立my.cnf
[root@rac1 ~]# cd /etc/
[root@rac1 etc]# touch my.cnf
[root@rac1 etc]# vi my.cnf
[mysqld]
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid
socket=/usr/local/mysql/mysql.sock
user=mysql
tmpdir=/tmp

3 配置mysqld命令
[root@rac1 etc]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@rac1 etc]# chmod 755 /etc/init.d/mysqld
[root@rac1 etc]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/mysql

4 開始安裝
[mysql@rac1 mysql]$ pwd
/usr/local/mysql
[mysql@rac1 mysql]$ ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp

[mysql@rac1 data]$ service mysqld status
MySQL is not running                                       [FAILED]

[mysql@rac1 data]$ service mysqld start
Starting MySQL..                                           [  OK  ]

5 mysql.sock
[mysql@rac1 bin]$ ./mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

[mysql@rac1 bin]$ ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock

6 登入mysql並修改密碼
[mysql@rac1 data]$ pwd
/usr/local/mysql/data
[mysql@rac1 data]$ vi error.log 
2018-06-04T03:51:14.789564Z 1 [Note] A temporary password is generated for root@localhost: k7deH1nLvo_N

[mysql@rac1 bin]$ ./mysql -uroot -p'k7deH1nLvo_N'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.21

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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by '123';
Query OK, 0 rows affected (0.10 sec)

[mysql@rac1 bin]$ ./mysql -uroot -p123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.21 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.19 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2155537/,如需轉載,請註明出處,否則將追究法律責任。

相關文章