【MySQL安裝】Linux下安裝MySQL(預編譯)
預編譯方式安裝MySQL
一、 環境說明
作業系統:Redhat Linux 7.2
MySQL 版本: 5.7
安裝介質: mysql-5.7.25-linux-glibc2.12-x86_64.tar .gz
二、 安裝MySQL 軟體
1. 建立使用者和組
# groupadd mysql
# useradd -g mysql - d / home /mysql mysql
# passwd mysql
2. 上傳壓縮包到/usr/local/ 目錄,解壓
# cd /usr/local/
# tar -xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
解壓後會生成一個mysql-5.7.25-linux-glibc2.12-x86_64 的資料夾
3. 建立軟連結
# ln -s mysql-5.7.25-linux-glibc2.12-x86_64 mysql
三、 初始化MySQL 資料庫
1. 建立目錄
# cd /usr/local/mysql
# mkdir mysql-files
# chmod 750 mysql-files/
2. 初始化資料庫
# cd /usr/local/mysql
# chown -R mysql:mysql .
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
注:basedir :指定 MySQL 的安裝目錄
datadir :指定 MySQL 的資料檔案目錄
2020-03-17T07:44:05.186790Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-17T07:44:05.629460Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-17T07:44:05.709511Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-17T07:44:05.773460Z 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: 140c9551-6823-11ea-ae76-0050563016cd.
2020-03-17T07:44:05.774908Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-03-17T07:44:05.776860Z 1 [Note] A temporary password is generated for
root@localhost: nwV/pWg:p5ko
(紅色字型就是初始root 密碼)
# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
Generating a 2048 bit RSA private key
.........................................................................+++
.........................................................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
.........................................................................+++
...............+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
.......................................+++
.+++
writing new private key to 'client-key.pem'
-----
# chown -R root .
# chown -R mysql data mysql-files/
3. 建立MySQL 配置檔案 my.cnf
(my.conf 檔案已經有了)
# mv /etc/my.cnf /etc/my.cnf.bak
# vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
4. 啟動MySQL
方法一:使用mysqld_safe (手動啟動)
# bin/mysqld_safe --user=mysql &
方法二:使用mysql.server 指令碼(將 mysqld 新增到服務中)
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start
Starting MySQL. SUCCESS!
[1] + Done bin/mysqld_safe --user=mysql
5. 檢視MySQL 程式
# ps -ef|grep mysql
mysql 7138 7024 0 08:28 ? 00:00:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql.err --pid-file=/usr/local/mysql/data/mysql.pid
注 :plugin-dir :外掛目錄
log-error :錯誤日誌
pid-file : pid 檔案
凡是沒有指定目錄的,都是放在data 目錄下
6. 修改環境變數
# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
# source /etc/profile
7. 登入mysql
# mysql -uroot -p'nwV/pWg:p5ko'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.25
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
8. 重置root 密碼
mysql> alter user root@'localhost' identified by 'P@ssw0rd';
(可以嘗試重新登入)
m ysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
9. 如果需要重新初始化[ 可選 ]
# service mysqld stop
# rm -rf /usr/local/mysql/data/
# cd /usr/local/mysql
# chown -R mysql:mysql .
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# bin/mysql_ssl_rsa_setup
# chown -R root.
# chown -R mysql data mysql-files
10. 可以在作業系統層面改密碼
# mysqladmin -u'root' -p'P@ssw0rd' password "qaq123"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
上述警告忽略
---- end ----
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31529886/viewspace-2747692/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql linux下安裝MySqlLinux
- Linux下編譯安裝Mysql 5.5的簡單步驟Linux編譯MySql
- Centos 7.6 下Mysql8.0.16編譯安裝CentOSMySql編譯
- 【mysql】linux下安裝mysql-5.7.31MySqlLinux
- Linux下安裝使用MySQLLinuxMySql
- Linux下安裝MySQL 5.7LinuxMySql
- Linux 下 docker 安裝 MySQLLinuxDockerMySql
- LNMP架構編譯安裝(Linux、Nginx、Mysql、PHP)LNMP架構編譯LinuxNginxMySqlPHP
- Linux安裝解除安裝MySQLLinuxMySql
- 【轉】MySQL原始碼編譯安裝MySql原始碼編譯
- 如何編譯安裝MySQL8.0編譯MySql
- 編譯安裝nginx-php-mysql編譯NginxPHPMySql
- Linux安裝MySQLLinuxMySql
- mysql安裝 for LinuxMySqlLinux
- ffmpeg安裝之linux編譯安裝Linux編譯
- orthanc 編譯安裝mysql S3編譯MySqlS3
- Cnetos7編譯安裝MySQL教程。編譯MySql
- 阿里雲mysql原始碼編譯安裝阿里MySql原始碼編譯
- MySQL5.7.16原始碼編譯安裝MySql原始碼編譯
- MySQL-01.Linux下MySQL安裝和使用MySqlLinux
- 基於Linux的MySQL5.7原始碼編譯安裝LinuxMySql原始碼編譯
- MySQL - 下載與安裝配置(Linux)MySqlLinux
- Linux下安裝Mysql資料庫LinuxMySql資料庫
- Linux-Ubuntu-mysql-安裝&解除安裝LinuxUbuntuMySql
- mysql在linux安裝MySqlLinux
- linux上安裝mysqlLinuxMySql
- Linux安裝mysql 8.0LinuxMySql
- 最新!linux mysql安裝LinuxMySql
- MySQL 8.0.21下載安裝教程及Navicat for MySQL安裝MySql
- 如何在Linux下編譯安裝MariaDBLinux編譯
- Linux 環境下編譯安裝 RedisLinux編譯Redis
- CentOS6.7下使用cmake編譯安裝MySQL5.5.32CentOS編譯MySql
- Ubuntu 16.04下 Mysql5.7.17原始碼編譯與安裝UbuntuMySql原始碼編譯
- MAC M3 編譯安裝mysql 5.7.44Mac編譯MySql
- MySQL免編譯安裝及登入(5.6.36)MySql編譯
- Linux 編譯安裝 PythonLinux編譯Python
- Linux編譯安裝NginxLinux編譯Nginx
- MySQL下載安裝MySql