centos安裝mysql的三種方式:
rpm安裝、原始碼 二進位制tar包 又稱二進位制glibc(無需編譯)、原始碼 tar包 (要編譯)
下面只介紹rpm安裝和二進位制glibc安裝
方法一:配置yum倉庫安裝(和方法二原理一樣,都是rpm安裝)
yum -y install
2、安裝
yum -y install mysql-community-server
3、啟動
systemctl start mysqld
4、檢視狀態
systemctl status mysqld
5、檢視初始密碼
grep 'temporary password' /var/log/mysqld.log
6、登入測試(用初始化密碼)
mysql -uroot -p
7、修改root登入密碼
alter user 'root'@'localhost' identified by '密碼';
flush privileges;
8、允許root遠端訪問
update mysql.user set host = '%' where user ='root';
wget
國內映象站(中國科學技術大學映象站)
wget mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar
2、解壓
tar -xvf mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar
3、安裝(各個rpm是有依賴的,所以要按順序安裝)
(1)rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm
(2)rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm
如果報錯:
error: failed dependencies:
mariadb-libs is obsoleted by mysql-community-libs-8.0.20-1.el7.x86_64
執行:yum -y remove mysql-libs再繼續安裝
(3)rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm
(4)rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm
如果報錯:
error: failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-8.0.20-1.el7.x86_64
libaio.so.1(libaio_0.1)(64bit) is needed by mysql-community-server-8.0.20-1.el7.x86_64
libaio.so.1(libaio_0.4)(64bit) is needed by mysql-community-server-8.0.20-1.el7.x86_64
執行:yum -y install libaio再繼續安裝
4、啟動
systemctl start mysqld
5、檢視狀態
systemctl status mysqld
6、檢視初始密碼
grep 'temporary password' /var/log/mysqld.log
7、登入測試(用初始化密碼)
mysql -uroot -p
8、修改root登入密碼
alter user 'root'@'localhost' identified by '密碼';
flush privileges;
9、允許root遠端訪問
update mysql.user set host = '%' where user ='root';
方法三:原始碼 二進位制tar包 又稱二進位制glibc 安裝
wget
國內映象站(中國科學技術大學映象站)
wget mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
2、解壓
tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
3、將解壓目錄移動到自定義目錄,並改名
mv mysql-8.0.21-linux-glibc2.12-x86_64 /usr/local/mysql
4、建立使用者組和使用者
groupadd mysql
useradd -r -g mysql mysql
5、建立配置檔案
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql # 基本路徑
datadir=/usr/local/mysql/data #資料路徑 (先在/usr/local/mysql建data目錄)
socket=/usr/local/mysql/data/mysql.sock # socket檔案
symbolic-links=0
log-error=/usr/local/mysql/data/mysqld.log #錯誤日誌
pid-file=/usr/local/mysql/data/mysqld.pid #pid檔案
[mysql]
socket=/usr/local/mysql/data/mysql.sock
6、配置環境變數
vim /etc/profile
export mysql_home=/usr/local/mysql
export mysql_path=$mysql_home/bin
export path=$path:$mysql_path
source /etc/profile
7、初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
報錯:error while loading shared libraries: libaio.so.1: cannot open shared object file: no such file or directory
原因:缺少libaio庫檔案
解決:執行yum install libaio* -y 再重新初始化
8、修改屬主屬組
chown -r mysql:mysql /usr/local/mysql
9、配置服務管理
cd /usr/local/mysql/support-files/
mv mysql.server /etc/init.d/mysqld
10、啟動,設定密碼
因為沒有初始密碼,用跳過授權表的方式來啟動mysql
mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
免密登入
mysql -uroot -p 不需要輸入密碼直接回車
flush privileges;
alter user 'root'@'localhost' identified by '密碼';
11、重啟驗證密碼
service mysqld restart
service mysqld status
12、允許root遠端訪問
mysql -uroot -p
update mysql.user set host = '%' where user ='root';
centos安裝mysql的三種方式
centos安裝mysql的三種方式 rpm安裝 原始碼 二進位制tar包 又稱二進位制glibc 無需編譯 原始碼 tar包 要編譯 下面只介紹rpm安裝和二進位制glibc安裝 方法一 配置yum倉庫安裝 和方法二原理一樣,都是rpm安裝 方法三 原始碼 二進位制tar包 又稱二進位制glibc...
CentOS下mysql的安裝
yum update公升級以後的系統版本為 root yl web yl cat etc redhat release centos linux release 7.1.1503 core yum install mysql yum install mysql server yum install ...
centos下的mysql安裝
解除安裝mysql yum remove mysql mysql server mysql libs compat mysql51 rm rf var lib mysql rm etc my.cnf 檢視是否還有mysql軟體 rpm qa grep mysql 先解除安裝乾淨才進行安裝mysql ...