一:到mysql官網下載最新的mysql包
二:在linux /usr/local/中解壓mysql壓縮包 改名爲mysql
# cd /usr/local/
# tar -xzvf mysql 壓縮包名
三:創建用戶組mysql,創建用戶mysql並將其添加到用戶組mysql中,並賦予讀寫權限
# groupadd mysql --創建mysql用戶組組
# useradd -r -g mysql mysql --創建mysql用戶並添加到mysql用戶組中
# chown -R mysql mysql/ --將mysql目錄訪問權限賦爲myql用戶
# chgrp -R mysql mysql/ --改變mysql目錄的用戶組屬於mysql組
四:創建配置文件 保存並退出
# 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 = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
#複製以下內容 結束-----------------------------------
五:初始化數據庫
# /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
看到有錯誤信息(第1次報錯)
2018-10-10 16:50:42 21449 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
於是上網找原因:
從報錯上來看,是由於缺少了mysql.plugin表所致的,不過現在連啓動都啓動不了,怎樣創建表呢?所以肯定是其他原因導致的,於時繼續網上找繼續試,最後找到了這個處理方法,進入mysql安裝後的目錄scripts執行以下語句:
# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
又報錯下,如下:(第2次報錯)
FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
Data::Dumper
好吧,繼續百度
解決方法 :安裝autoconf庫
# yum -y install autoconf //此包安裝時會安裝Data:Dumper模塊
六、配置環境變量
在文件中增加以下兩行:
export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
七、讓環境變量生效
#source /etc/profile
八、添加自啓動服務
#chkconfig --add mysql
#chkconfig mysql on
九、啓動mysql
#cd /user/local/mysql/bin
#service mysql start
十、增加root用戶密碼:
#cd /user/local/mysql/bin
#mysqladmin -u root password 'hww123456'
如果報mysqladmin:command not found
# ln -s /user/local/mysql/bin/mysql /usr/bin
# ln -fs /user/local/mysql/bin/mysql mysql
十一、登錄mysql 創建用戶並賦予所有權限使得遠程可以訪問
#mysql -u root -p
#GRANT ALL PRIVILEGES ON *.* TO test@"%" IDENTIFIED BY "123456";
後面按照上面的方式安裝不成功了,不知道啥原因,又有了下面的方式,步驟 一,二,三 是一樣的
cd mysql/scripts
[root@localhost scripts]# ./mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper
# yum -y install autoconf //此包安裝時會安裝Data:Dumper模塊
[root@localhost scripts]# ./mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql
Installing MySQL system tables...2019-03-28 16:08:27 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-03-28 16:08:27 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release.
2019-03-28 16:08:27 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a future release.
2019-03-28 16:08:27 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release.
2019-03-28 16:08:27 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-03-28 16:08:27 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.41) starting as process 4649 ...
/啓動腳本
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
==========/et/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 = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
==============================
[root@localhost mysql]# /etc/init.d/mysqld start
//修改root用戶的密碼
[root@localhost scripts]# cd /usr/local/mysql/bin/
[root@localhost bin]# mysqladmin -u root password '123456'
[root@localhost bin]# 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.6.41 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> GRANT ALL PRIVILEGES ON *.* TO test@"%" IDENTIFIED BY "123456";
Query OK, 0 rows affected (0.09 sec)
//登錄mysql 創建用戶並賦予所有權限使得遠程可以訪問
GRANT ALL PRIVILEGES ON *.* TO test@"%" IDENTIFIED BY "123456";