安裝mySQL(我安裝的是mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz)
先檢查系統自帶的mysql:
rpm –qa|grep –i mysql
#rpm -qa |grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64
解除安裝掉:
rpm-e --nodeps mysql-libs-5.1.71-1.el6.x86_64
建立mysql使用者群組
groupadd mysql
useradd -r -g mysql mysql
解壓mysql到指定安裝目錄下,一般選擇/usr/local/,這裡選擇/home/mysql:
#cd /home/mysql
#tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64
###更改授權給mysql使用者群組
[[email protected]]#chown -R mysql:mysql mysql-5.7.22-linux-glibc2.12-x86_64
接下來配置mysql配置檔案,内容如下(紅字為必要添加的内容):
[[email protected]]# vi /etc/my.cnf
# For advice on how to change settingsplease see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's atemplate which will be copied to the
# *** default location during install, andwill be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount ofRAM for the most important data
# cache in MySQL. Start at 70% of total RAMfor dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a veryimportant data integrity option: logging
# changes to the binary log betweenbackups.
# log_bin
# These are commonly set, remove the # andset as required.
basedir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64
datadir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/data
max_allowed_packet=200M
# port = .....
# server_id = .....
# socket = .....
character_set_server =utf8
init_connect = 'SET NAMESutf8'
# Remove leading # to set options mainlyuseful for reporting servers.
# The server defaults are faster fortransactions and fast SELECTs.
# Adjust sizes as needed, experiment tofind the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
[mysql]
default-character-set =utf8
[mysql.server]
default-character-set =utf8
[mysqld_safe]
default-character-set =utf8
[client]
default-character-set =utf8
将mysql配置檔案配置到環境變量,添加到/etc/profile中
vim /etc/profile
在PATH中添加mysql的安裝目錄和bin目錄:
/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64:/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/bin:
添加位置如下:
重新開機伺服器或source /etc/profile使配置檔案生效,添加mysql服務開機啟動
cp -ar /home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysqld
接下來使用mysql使用者初始化資料庫
cd /home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64
mkdir data
bin/mysql_install_db --user=mysql --basedir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64 --datadir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/data
啟動mysql服務:
service mysqld start
修改root密碼(如果mysqladmin修改root密碼報錯,請參考https://blog.csdn.net/u012206025/article/details/80927778):
cd /home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/bin
mysqladmin -uroot password '[email protected]'
登陸檢視字元集:
mysql -uroot –p
然後輸入密碼回車進入資料庫:
檢視字元集設定是否正确:
show variables like '%character%';
開啟遠端連接配接:選擇要使用的mysql資料庫,修改遠端連接配接的基本資訊。
use mysql
更改遠端連接配接設定:
GRANTALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '[email protected]' WITH GRANTOPTION;
重新整理剛才修改的權限,使其生效
flush privileges;
檢視修改是否成功:
select host,user from user;
有紅框裡的東西就成功,退出重新開機mysql。
退出mysql:mysql>quit
service mysqld restart
Mysql至此安裝完畢,安裝mysql比較容易出錯,我們隻要根據mysql的data目錄下生成的xxxx.err日志檔案資訊來調整就行了。