mysql5.7.28tar包安裝

mysql給root開啓遠程訪問權限

mysql5.7.28tar包安裝

下載數據庫tar包,地址:https://dev.mysql.com/downloads/mysql/5.7.html
在這裏插入圖片描述

下載前先查看linxu系統的位數

如何查看linux是32位還是64位
使用命令 getconf LONG_BIT
如果返回的是32,那麼就是32位
如果返回的是64,那麼就是64位

#卸載系統自帶的Mariadb

[root@ ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

#刪除etc目錄下的my.cnf文件

[root@ ~]# rm -rf /etc/my.cnf

檢查mysql是否存在

[root@ ~]# rpm -qa | grep mysql
[root@ ~]#

檢查mysql組和用戶是否存在,如無創建
linux如何查看所有的用戶和組信息?

[root@ ~]# cat /etc/group | grep mysql
[root@ ~]# cat /etc/passwd | grep mysql

創建mysql用戶組

[root@localhost mysql-5.7.28]# groupadd mysql

創建一個用戶名爲mysql-3306的用戶並加入mysql用戶組

[root@localhost mysql-5.7.28]# useradd -g mysql mysql-3306
[root@localhost mysql-5.7.28]# passwd mysql-3306

制定password 爲 yjw@2018 (密碼不可太簡單,會校驗不過的哦)

[root@~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

解壓tat包 我的路徑 /usr/local/mysql/

[root@localhost mysql]# tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-3306

更改所屬的組和用戶

[root@localhost mysql]# chown -R mysql-3306 mysql-3306/
[root@localhost mysql]# chgrp -R mysql mysql-3306/
[root@localhost mysql]# cd mysql-3306/
[root@localhost mysql]# mkdir data

在/etc文件編輯my.cnf文件


[mysql]

# 設置mysql客戶端默認字符集

default-character-set=utf8 

[mysqld]

skip-name-resolve

#設置3306端口

port =3306

# 設置mysql的安裝目錄

basedir=/usr/local/mysql/mysql

# 設置mysql數據庫的數據的存放目錄

datadir=/usr/local/mysql/mysql/data

# 允許最大連接數

max_connections=200

# 服務端使用的字符集默認爲8比特編碼的latin1字符集

character-set-server=utf8

# 創建新表時將使用的默認存儲引擎

# default-storage-engine=INNODB 

lower_case_table_names=1

max_allowed_packet=16M

在/user/local/mysql/mysql/support-files文件編輯mysql.server文件

  basedir=/usr/local/mysql/mysql
  bindir=/usr/local/mysql/mysql/bin
  if test -z "$datadir"
  then
    datadir=/usr/local/mysql/mysql/data
  fi
  sbindir=/usr/local/mysql/mysql/bin
  libexecdir=/usr/local/mysql/mysql/bin

初始化數據庫 (數據庫目錄不要用特殊字符,最好常規名稱,避免不必要的麻煩)

以下已經棄用,僅做記錄;
[root@localhost mysql-3306]# bin/mysql_install_db --user=mysqltest --basedir=/user/local/mysql/mysql/ --datadir=/user/local/mysql/mysql/data/
2019-11-21 12:28:51 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-11-21 12:28:51 [ERROR] Can’t locate the language directory.

網上查詢顯示新版本數據庫以上方法已經棄用,可用一下方法,親測可用;
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql/ --datadir=/usr/local/mysql/mysql/data/
2019-11-22T10:20:11.275791Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-22T10:20:11.742089Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-22T10:20:11.804639Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-22T10:20:11.864495Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: aac1a7b6-0d11-11ea-a376-000c29210e9a.
2019-11-22T10:20:11.865862Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2019-11-22T10:20:13.410072Z 0 [Warning] CA certificate ca.pem is self signed.
2019-11-22T10:20:13.696971Z 1 [Note] A temporary password is generated for root@localhost: XVaf93Xk%)GF

默認密碼:(XVaf93Xk%)GF)

#設置開機啓動

[root@localhost mysql]#  chkconfig --level 35 mysqld on
[root@localhost mysql]#  chkconfig --list mysqld

[root@localhost mysql]#  chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql]#  chkconfig --add mysqld
[root@localhost mysql]#  chkconfig --list mysqld
[root@localhost mysql]#  service mysqld status
SUCCESS! MySQL running (7099)

etc/profile/
linux系統中給mysql配置環境變量

export PATH=$PATH:/usr/local/mysql/mysql/bin   設置環境變量後,mysql可以再任意目錄登錄
[root@localhost mysql]# source /etc/profile

初始化MySQL密碼

mysqladmin -uroot -p'XVaf93Xk%)GF' password

[root@localhost mysql]# bin/mysqladmin -uroot -p'XVaf93Xk%)GF' password
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
New password: 
Confirm new password: 
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

查看端口: netstat -tunlp

查看服務狀態:

[root@localhost mysql]# service mysql status
 SUCCESS! MySQL running (7099)

遇到的問題 -------------------------------------------------------------------------


my.cnf文件  文件的 default-storage-engine=INNODB 是會報如下錯誤:

[root@localhost mysql-3306]# bin/mysqld --initialize --user=mysql-3306 --basedir=/usr/local/mysql-5.7.28/mysql-3306/ --datadir=/usr/local/mysql-5.7.28/mysql-3306/data/
2019-11-21T08:40:50.652204Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-21T08:40:50.967610Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-21T08:40:51.013205Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-21T08:40:51.068645Z 0 [ERROR] Unknown/unsupported storage engine: INNODB
2019-11-21T08:40:51.068674Z 0 [ERROR] Aborting

[root@localhost mysql-3306]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql-5.7.28/mysql-3306/data/localhost.localdomain.err'.
 ERROR! The server quit without updating PID file (/usr/local/mysql-5.7.28/mysql-3306/data/localhost.localdomain.pid).
[root@localhost mysql-3306]# bin/mysql -uroot -p
Enter password: 
mysql: Character set 'utf8' is not a compiled character set and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mysql提示Character set ‘utf-8’ is not a compiled character set and is not specified:

[root@localhost mysql]# vim /etc/profile
[root@localhost mysql]# source /etc/profile
[root@localhost mysql]# mysql -v
mysql: Character set 'utf8' is not a compiled character set and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file
mysql: Character set 'utf8' is not a compiled character set and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file
ERROR 2019 (HY000): Can't initialize character set utf8 (path: /usr/local/mysql/share/charsets/)
[root@localhost mysql]# mysq
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章