mysql5.7.21源碼安裝

1.下載安裝包

MySQL 官方下載地址: https://dev.mysql.com/downloads/mysql/ 
 

2.安裝依賴包

MySQL依賴於libaio 庫。若是這個庫沒有在本地安裝,數據目錄初始化和後續的服務器啓動步驟將會失敗。請使用適當的軟件包管理器進行安裝。例如,在基於Yum的系統上:
shell> yum search libaio 
shell> yum install libaio
 

3.建立一個mysql用戶和組

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
 

4.解壓到指定目錄

shell> tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local
shell> cd /usr/local
shell> mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
 

5.配置數據庫目錄

數據目錄:/usr/local/mysql/data 
參數文件my.cnf:/usr/local/mysql/etc/my.cnf 
錯誤日誌log-error:/usr/local/mysql/log/mysql_error.log 
二進制日誌log-bin:/usr/local/mysql/log/mysql_bin.log 
慢查詢日誌slow_query_log_file://usr/local/mysql/log/mysql_slow_query.log 
套接字socket文件:/usr/local/mysql/run/mysql.sock 
pid文件:/usr/local/mysql/run/mysql.pid 
 
shell> mkdir -p /usr/local/mysql/{data,log,etc,run}
shell> chown -R mysql:mysql /usr/local/mysql 
shell> chmod 750 /usr/local/mysql/{data,log,etc,run}
 

6.配置my.cnf文件

在/usr/local/mysql/etc/下建立my.cnf文件,加入以下參數,其餘參數根據須要配置
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
 
[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 128M
max_connections = 2048
open_files_limit = 65535
 
skip-name-resolve
lower_case_table_names=1
 
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
 
 
innodb_buffer_pool_size = 128M
innodb_log_file_size = 128M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
 
 
key_buffer_size = 16M
 
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/log/mysql_bin.log
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
 
 
tmp_table_size = 16M
max_heap_table_size = 16M
query_cache_type = 0
query_cache_size = 0
 
server-id=1
 

7.設置臨時密碼

grep 'temporary password' /usr/local/mysql/log/mysql_error.log
 

8.初始化

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data --initialize
 
9.將mysqld設置開啓自動啓動
 
cp /usr/local/mysql/support-files/mysql.server    /etc/init.d/mysqld
chkconfig --add mysqld
 
10.複製配置文件my.cnf
 
cp /usr/local/mysql/etc/my.cnf    /etc/my.cnf  (提示覆蓋就覆蓋)
 
11.啓動mysql服務
 
 
 
12.進入mysql
cd /usr/local/mysql/bin 
./ mysql -u root -p(臨時密碼)
 
13.修改密碼
從新設置密碼
SET PASSWORD FOR'root'@localhost=PASSWORD('admin');   #對應的換成你本身的密碼便可
1四、開啓遠程權限
 
grant all privileges on *.* to '新用戶名'@'%' identified by '新密碼';
flush privileges;
 
15.配置環境變量
 
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
 
實戰備註:
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
 
報錯解決方案
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install -y libaio  //安裝後在初始化就OK了
 
cRowiC5?_mo_
linux mysql password
set password for 'root'@'localhost'=password('Jackphp123!')
 
錯誤提示:
 
[root@localhost support-files]# ./mysql.server start
 
Starting MySQL.2017-07-10T07:02:40.832128Z mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log‘, however file don‘t exists. Create writable for user ‘mysql‘.
 ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
 解決方案:
 
由於前期未建立 /var/log/mariadb/mariadb.log‘ 下面的 mariadb目錄 ,mariadb.log 須要手工建立,完成 啓動成功。

缺乏libtinfo.so.5解決辦法 

在CentOS下,輸入命令
ln -s /usr/lib/libncurses.so.5 /usr/lib/libtinfo.so.5 
ln -s /usr/lib/libncurses.so.5 /lib/libtinfo.so.5  
安裝mysql後登陸提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:yes)
解決以下:
1.中止mysql服務
systemctl stop mysqld.service
 
2.修改配置文件無密碼登陸
vim  /etc/my.cnf
在最後加上
skip-grant-tables
保存
3.啓動mysql
systemctl  start  mysqld.service
 
4.登陸mysql
mysql -u root
注意這裏不要加-p
5.修改密碼,mysql5.7用此語法
use mysql;
update mysql.user set authentication_string=password('123456') where user='root' ;  
6.回到第二部把剛加的那句刪掉
保存,重啓mysql就能夠了
 
默認配置文件路徑: 
配置文件:/etc/my.cnf 
日誌文件:/var/log//var/log/mysqld.log 
服務啓動腳本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid
 
錯誤緣由:升級了mysql沒有update相應的mysql系統表結構,update完畢後重啓既可解決
相關文章
相關標籤/搜索