CentOS 7 安裝 mysql-5.7.14

在centos7上安裝 路上遇過各種坑 把在centos7正確安裝mysql-5.7.14分享一下

1. CentOs7 默認的數據庫為MariaDB,先卸載MariaDB,否則安裝mysql,引起沖突

rpm -qa  mariadb
rpm -e --nodeps  mariadb

2. 準備好工作環境 mkdir /application #此目錄用來存放需要另外存放的應用程序安裝目錄

3. 創建mysql用戶組與用戶,并下載安裝包

groupadd mysql
useradd -g mysql  -s /sbin/nologin  -M mysql 

id mysql
uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)

PS.如果已經存在提示錯誤了  可以先刪除

cd /application  下載安裝包,
我這里安裝的是,mysql-5.7.16.tar.gz
wget -c http://192.168.42.26/install_package/down/mysql-5.7.16.tar.gz

4. 解壓并安裝mysql

tar xf mysql-5.7.16.tar.gz 
ls
mysql-5.7.16-linux-glibc2.5-x86_64  mysql-5.7.16.tar.gz  
mv mysql-5.7.16-linux-glibc2.5-x86_64  mysql-5.7.16  


cd mysql 
[root@test mysql]# ls
bin  COPYING  docs  include  lib  man  mysql  README  share  support-files

我要把整個mysql都安裝在/application目錄里,下面是初始化mysql mysql5.7之前使用./bin/mysql_install_db –user=mysql –basedir=[install dir] –datadir=[data dir] 命令,但是 5.7以后已經放棄mysql_install_db,使用新的mysqld

[root@test mysql-5.7.16]#  ./bin/mysqld --user=mysql --basedir=/application/mysql-5.7.16/ --datadir=/application/mysql-5.7.16/data  --initialize
2017-05-07T02:11:06.891174Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-05-07T02:11:09.101667Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-05-07T02:11:09.572053Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-05-07T02:11:09.795916Z 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: 6fc38e6f-32ca-11e7-9717-000c29c8721f.
2017-05-07T02:11:09.812070Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-05-07T02:11:09.827010Z 1 [Note] A temporary password is generated for root@localhost: iRctOTz9sr--

特別要注意最后的密碼,是進入mysql的密碼

PS.如果你的data文件有內容 會報

[ERROR] --initialize specified but the data directory has files in it. Aborting.

這個錯誤 正確的是把data文件清空 rm -rf *

mv /etc/my.cnf /etc/my.cnf.back.old
cd support-files/ 
cp my-default.cnf /etc/my.cnf
cp mysql.server  /etc/init.d/mysqld

[root@test application]# ln -s mysql-5.7.16 mysql
[root@test application]# ls
mysql  mysql-5.7.16  mysql-5.7.16.tar.gz  svndata  svnpasswd


[root@test support-files]# service mysqld start
/etc/init.d/mysqld: line 251: my_print_defaults: command not found
/etc/init.d/mysqld: line 271: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

因為默認的目錄是/usr/local/mysql 我們換了別的目錄 我們修改 vim /etc/my.cnf 

basedir=/application/mysql
datadir=/application/mysql/data
整體配置如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /application/mysql ######
datadir = /application/mysql/data ###
port = 3306 ###
# server_id = .....
socket =/var/lib/mysql/mysql.sock ###


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

character_set_server=utf8 ###
init_connect='SET NAMES utf8' ###

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


[client]
default-character-set=utf8
socket =/var/lib/mysql/mysql.sock

進行修改成現在的目錄 之后 ESC , :號后wq回車 保存退出

5. 啟動MySQL

[root@test application]# service mysqld start
Starting MySQL.... SUCCESS!

6.加入開機自啟動

[root@test application]# systemctl is-enabled mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld --level=5
disabled

systemctl enable  mysqld


[root@test application]# systemctl is-enabled mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld --level=5
enabled

7. 添加環境變量vim /etc/profile.d/mysql.d

export  PATH=$PATH:/application/mysql/bin

logout  退出重新登錄

8.更改msyql密碼

[root@test ~]# mysql -u root -p
Enter password: [輸入安裝時的密碼]
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16

Copyright (c) 2000, 2016, 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> use mysql 
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

執行任何命令都提示要更改密碼

set password for 'root'@'localhost'=password('root'); ##輸入這條命令即可

我們也可以通過mysqladmin來改密碼 mysqladmin -u root -h localhost password ‘root’ -p ##按照提示操作即可,需要輸入舊密碼

重啟mysql

9.如果我們想直接通過mysql命令進入mysql,又必須需要密碼,怎么辦,我們可以這樣做,在root家目錄創建 隱藏文件.my.cnf,編輯如下,運行mysql命令即可

[client]
default-character-set=utf8
socket =/var/lib/mysql/mysql.sock
user=root
host=localhost
password=root

運行mysql命令,直接進入

[root@test ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

至此,mysql的安裝已經完成

原創文章,作者:srayban,如若轉載,請注明出處:http://www.www58058.com/74880

(2)
sraybansrayban
上一篇 2017-05-07
下一篇 2017-05-07

相關推薦

  • bash腳本入門之變量、運算、條件測試

    概述     腳本編程能力是作為運維工程師不可或缺的一項基本技能,各種系統的運維,如果完全靠命令行一條一條命令來執行,工作效率可想而知,而腳本卻可以將完成一定功能的各個命令依據一定的流程控制,邏輯判斷去完成某種功能,提升工作效率。本章就簡單介紹一些linux下的bash腳本編程的基礎入門知識,具體內容分為以下幾個方面:…

    Linux干貨 2016-08-12
  • nginx 日志切割(腳本實現)

        這里主要介紹nginx日志切割.(訪問日志與錯誤日志)     準備好一臺機器,配置隨意,安裝nginx應用。     1. nginx安裝步驟   # tar xf nginx-1…

    Linux干貨 2016-07-10
  • linux進程及作業管理

    linux進程及作業管理 cpu指令權限等級: 特權級也叫hierarchical protection domains, 有的也叫用戶態. 是一種用來保護數據和阻止惡意行為的機制. 電腦操作系統提供不同權限訪問級別的資源. 特權級分為四級, 特權級0,1,2,3. 在windows中只使用特權級0和特權級3, 特權最高的是特權級0, 可以直接操作硬件, 如…

    Linux干貨 2016-09-19
  • 磁盤及文件系統管理

    磁盤管理     MBR:master boot record 主引導記錄。位于磁盤的0磁道0扇區共512字節,獨立于操作系統之外的。512字節的劃分               …

    Linux干貨 2016-08-25
  • 基礎命令

    1,對于Linux的實驗環境我們要用到虛擬機,往往每次上線都要登錄,這時候如果把用戶設為自動登錄就會方便許多,接下來就介紹下設置虛擬機的自動登錄 , /etc/gdm/custom.conf 這個就是設置自動登錄的一個配置文件,我們先來使用nano打開這個文件,如下 # GDM configuration storage 這是GDM的一個配置存儲 [daem…

    2017-11-19
  • linux權限管理

          今天來講講linux里面權限的問題,在linux系統中,有這么幾類權限,r,w,x,s,t這么幾類權限,系統中為什么要有權限這個東西呢,linux一切皆文件,有些文件不想讓某些人看到,那么這個時候就需要設置文件的訪問的權限了,文件的擁有者一般都是有權力修改刪除文件的,但擁有者以外的人未必就能刪除修…

    Linux干貨 2016-08-04
欧美性久久久久