解壓包安裝方式
一握恳、安裝向導
1.系統(tǒng)約定
安裝文件下載目錄:/data/software
Mysql目錄安裝位置:/usr/local/mysql
數(shù)據(jù)庫保存位置:/data/mysql
日志保存位置:/data/log/mysql
2.下載mysql
在官網(wǎng):http://dev.mysql.com/downloads/mysql/中,選擇以下版本的mysql下載捺僻,完成后執(zhí)行以下解壓命令:
tar -zxf mysql-5.7.16-linux-glibc2.5-i686.tar.gz
3.解壓壓縮包到目標位置
mkdir /usr/local/mysql
mv mysql-5.7.16-linux-glibc2.5-i686 /usr/local/mysql
4.創(chuàng)建數(shù)據(jù)倉庫目錄
mkdir –p /data/mysql
ls/data/
5.新建mysql用戶乡洼、組及目錄
groupadd mysql
useradd -g mysql mysql
6.改變目錄屬有者
chmod a+xrw /usr/local/mysql/
chmod a+xrw /usr/local/mysql
(上面授權mysql文件夾讀寫權限很重要崇裁,會直接導致mysql.sock文件能否正常生成)
cd /usr/local/mysql?
chown -R mysql:mysql /data/mysql
chown –R mysql
chgrp –R mysql
chown -R mysql /data/mysql
7.配置參數(shù)
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
期間會出現(xiàn)一些缺少系統(tǒng)庫的提示(請參考后面的常見錯誤處理)
此處需要注意記錄生成的臨時密碼,如:YLi>7ecpe;YP
bin/mysql_ssl_rsa_setup --datadir=/data/mysql
8.修改系統(tǒng)配置文件
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql
修改以下內容:
basedir=/usr/local/mysql
datadir=/data/mysql
vim/etc/my.cnf
修改以下內容:
此處內容較多束昵,具體可以參考附錄里面的樣式進行設置拔稳。
9.啟動mysql
添加啟動軟連接:ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql? (移除軟連接:rm -rf /usr/bin/mysql)
cd /usr/local/mysql
bin/mysqld_safe --user=mysql &
bin/mysql--user=root –p--輸入第6步生成的臨時密碼
(./bin/mysql-u root -p)
此處可能出現(xiàn)錯誤提示
錯誤提示:
ERROR1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解決方法:
bin/mysql -hlocalhost -uroot -p ? ? #--輸入第6步生成的臨時密碼
登錄成功之后修改root密碼
mysql>set password=password('123456');
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host' from user where user='root';
mysql>exit
10.添加系統(tǒng)路徑
vi /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
11.配置mysql自動啟動
chmod755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
二、常見錯誤處理
1.缺庫
bash:/usr/local/bin/rar: /lib/ld-linux.so.2: bad ELF interpreter: No such file ordirectory
yuminstall glibc.i686
errorwhile loading shared libraries: libstdc++.so.6: cannot open shared object file:No such file or directory
yuminstall libstdc++.so.6
errorwhile loading shared libraries: libaio.so.1: cannot open shared object file: Nosuch file or directory
yum install libaio*
error while loading shared libraries: libncurses.so.5: cannot open shared object file
yum install? libncurses.so.5
2.?解決Navicat 報錯:1130-host is not allowed MySQL不允許從遠程訪問的方法
1. /usr/local/mysql/bin/>mysql -h localhost -u root -p ? ? ?//這樣應該可以進入MySQL服務器?
2. ?mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; ? ? ??//賦予任何主機訪問數(shù)據(jù)的權限?
3. mysql>FLUSH PRIVILEGES; ? ? ? ? //修改生效?
4. mysql>exit ? ?//退出MySQL服務器?
3.?ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysql/tmp/mysql.sock'
? ?a.查看是否開啟服務
# ps -ef | grep mysql
root? ? ? 5605? 5457? 0 11:45 pts/2? ? 00:00:00 grep mysql
? ?b.查看my.cnf (參考附錄重新編輯配置文件)
? ?c.啟動mysql服務器
# ./mysqld --defaults-file=/etc/my.cnf --user=root &
? ?d?.查看是否開啟服務
# ps -ef | grep mysql
root? ? ? 5359? ? 1? 0 11:42 ?? ? ? ? 00:00:00 ./mysqld --defaults-file=/etc/my.cnf --user=root
root? ? ? 5605? 5457? 0 11:45 pts/2? ? 00:00:00 grep mysql
三锹雏、附錄
1. my.conf配置內容參考
# For advice on how to changesettings please see
#http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It'sa template which will be copied to the
# *** default location duringinstall, and will be replaced if you
# *** upgrade to a newer versionof MySQL.
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
#character-set-server = utf8
[mysql]
no-auto-rehash
[mysqld]
# Remove leading # and set to theamount of RAM for the most important data
# cache in MySQL. Start at 70% oftotal RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on avery important data integrity option: logging
# changes to the binary logbetween backups.
# log_bin
# These are commonly set, removethe # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
# server_id = .....
socket = /usr/local/mysql/mysql.sock
# Remove leading # to set optionsmainly useful for reporting servers.
# The server defaults are fasterfor transactions and fast SELECTs.
# Adjust sizes as needed,experiment to find the optimal values.
join_buffer_size = 64M
sort_buffer_size = 16M
read_rnd_buffer_size = 2M
#lower_case_file_system = ON
#lower_case_table_names = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
RPM方式安裝
一巴比、環(huán)境準備?
1.官方下載地址:
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar
2.解壓:
tar -xvf?mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar
3.卸載之前的版本
rpm -qa | grep -i mysql
rpm -e xxxxx [之前安裝的版本] --nodeps 要卸載的mysql版本
4.安裝依賴組件
yum -y install libaio /?yum install libaio*
yum -y install net-tools
yum -y install?perl
yum -y install libaio.so.1
二、按照步驟安裝應用
1.rpm -ivh mysql-community-common-5.7.20-1.el6.x86_64.rpm --nodeps --force
2.rpm -ivh mysql-community-libs-5.7.20-1.el6.x86_64.rpm --nodeps --force
3.rpm -ivh mysql-community-devel-5.7.20-1.el6.x86_64.rpm --nodeps --force
4.rpm -ivh mysql-community-client-5.7.20-1.el6.x86_64.rpm??--nodeps --force
5.rpm -ivh mysql-community-server-5.7.20-1.el6.x86_64.rpm??--nodeps --force
三礁遵、查看轻绞、啟動、停止數(shù)據(jù)庫
# 查看mysql是否啟動service?
mysqld status
或者?
service mysql status
# 啟動mysqlservice?
mysqld start
或者
service mysql start
# 停止mysqlservice?
mysqld stop
# 重啟mysqlservice?
mysqld restart
四佣耐、修改密碼?(有點特殊?)
1.查看臨時密碼
grep password /var/log/mysqld.log
服務器回應:
2017-09-01T16:43:10.889769Z 1 [Note] A temporary password is generated for root@localhost: hcLMTxbOh2?w
這樣我們得知臨時密碼是:hcLMTxbOh2?w
2. 修改密碼
# 登錄mysql政勃,之后需要輸入密碼
mysql -p
# 設置新密碼(數(shù)據(jù)庫的密碼需要滿足以下條件:大小寫字母,數(shù)字和特殊符號)
set password = password("Mysql_123456");
# 退出當前登錄
quit;
3.測試
mysql -uroot -p
enter password:Mysql_123456
五兼砖、異常處理
1.??登錄異常:Can't connect to local MySQL server through socket '/tmp/mysql.sock'
[root@localhost /]# find / -name mysql.sock
/var/lib/mysql/mysql.sock
#我們需要修改my.cnf文件
[root@localhost /]# vi /etc/my.cnf
[client]
port??? = 3306
socket? = /var/lib/mysql/mysql.sock
……
保存之后即出奸远,重新啟動mysql...