linux 安裝MySql 5.7.20

一、下載文件(https://pan.baidu.com/s/1c1VBcHy)放到目錄:/usr/local/mysql

二、解壓linux

  cd /usr/local/
  tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz.tar.gz
  mkdir mysql   mv mysql
-5.7.20-linux-glibc2.12-x86_64/* mysql   groupadd mysql //建立用戶組mysql   useradd -r -g mysql mysql //-r參數表示mysql用戶是系統用戶,不可用於登陸系統,建立用戶mysql並將其添加到用戶組mysql中   chown -R mysql mysql/   chgrp -R mysql mysql/

三、建立配置文件sql

 vim /etc/my.cnf

 內容以下,能夠添加你須要的配置:數據庫

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#不區分大小寫
lower_case_table_names = 1vim

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONsocket

max_connections=5000spa

default-time_zone = '+8:00'rest

保存內容,按esc輸入以下命令日誌

:wq!

四、初始化數據庫code

#先安裝一下這個東東,要否則初始化有可能會報錯
yum install libaio
#手動編輯一下日誌文件,什麼也不用寫,直接保存退出
cd /var/log/

vim mysqld.log
:wq

chmod 777 mysqld.log
chown mysql:mysql mysqld.log

/usr/local/mysql/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

五、查看初始密碼

cat /var/log/mysqld.log

執行後關注最後一點:root@localhost: 這裏就是初始密碼

六、啓動服務,進入mysql,修改初始密碼,運行遠程鏈接(這裏執行完後,密碼將變成:123456)

cd /var/run/
mkdir mysqld
chmod 777 mysqld
cd mysqld
vim mysqld.pid

chmod 777 mysqld.pid
chown mysql:mysql mysqld.pid

/usr/local/mysql/support-files/mysql.server start /usr/local/mysql/bin/mysql -uroot -p你在上面看到的初始密碼
// 如下是進入數據庫以後的sql語句 use mysql; UPDATE `mysql`.`user` SET `Host`
='%', `User`='root', `Select_priv`='Y', `Insert_priv`='Y', `Update_priv`='Y', `Delete_priv`='Y', `Create_priv`='Y', `Drop_priv`='Y', `Reload_priv`='Y', `Shutdown_priv`='Y', `Process_priv`='Y', `File_priv`='Y', `Grant_priv`='Y', `References_priv`='Y', `Index_priv`='Y', `Alter_priv`='Y', `Show_db_priv`='Y', `Super_priv`='Y', `Create_tmp_table_priv`='Y', `Lock_tables_priv`='Y', `Execute_priv`='Y', `Repl_slave_priv`='Y', `Repl_client_priv`='Y', `Create_view_priv`='Y', `Show_view_priv`='Y', `Create_routine_priv`='Y', `Alter_routine_priv`='Y', `Create_user_priv`='Y', `Event_priv`='Y', `Trigger_priv`='Y', `Create_tablespace_priv`='Y', `ssl_type`='', `ssl_cipher`='', `x509_issuer`='', `x509_subject`='', `max_questions`='0', `max_updates`='0', `max_connections`='0', `max_user_connections`='0', `plugin`='mysql_native_password', `authentication_string`='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9', `password_expired`='N', `password_last_changed`='2017-11-20 12:41:07', `password_lifetime`=NULL, `account_locked`='N' WHERE (`User`='root');

flush privileges;

#若是提示必需要修改密碼才能夠進行操做的話則執行下面操做
 set password=password('新密碼');
flush privileges;
UPDATE `mysql`.`user` SET `Host` = '%',  `User` = 'root'  WHERE (`Host` = 'localhost') AND (`User` = 'root');

七、開機自啓

cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld

八、使用service mysqld命令啓動/中止服務

例如個人mysql:啓動/中止/暫停:

su - mysqlservice mysqld start/stop/restart
相關文章
相關標籤/搜索