目錄
一、首先安裝可以根據(jù)官方文檔進行安裝
二、Linux中安裝mysql
1、首先執(zhí)行二進制文件的安裝
一、首先安裝可以根據(jù)官方文檔進行安裝
https://dev.mysql.com/doc/
1、先安裝到Windows中:
?2、選擇mysql?community?server。
3、 選擇要下載的版本,到時候使用Linux中的ftp軟件上傳。推薦選擇5.7版本的,因為老,穩(wěn)定,很多公司都在使用。
4、 然后接下來是可以根據(jù)官方文檔安裝到Linux中:
二、Linux中安裝mysql
1、安裝mysql:準備一臺新的虛擬機,沒有安裝過mysql的。然后先使用xfs將mysql的壓縮包下載到Linux中(隨便的路徑都可以)
2、然后先使用xfs將mysql的壓縮包下載到Linux中(隨便的路徑都可以)。我們是實現(xiàn)二進制文件進行安裝:也有一個腳本文件的安裝。那我們待會就可以準備一臺克隆機來使用腳本安裝。
1、首先執(zhí)行二進制文件的安裝
1、修改主機名:為了方便識別
[root@nginx-kafka02 opt]# hostnamectl set-hostname sc-mysql
[root@nginx-kafka02 opt]# su - root 切換用戶進行生效
上一次登錄:五 7月 29 09:19:53 CST 2022從 192.168.2.118pts/0 上
2、解決軟件的依賴關(guān)系。
yum install cmake ncurses-devel gcc gcc-c++ vim lsof bzip2 openssl-devel ncurses-compat-libs -y
[root@sc-mysql ~]# yum install cmake ncurses-devel gcc gcc-c++ vim lsof bzip2 openssl-devel ncurses-compat-libs -y
已加載插件:fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 6.2 kB 00:00:00
* base: mirrors.nju.edu.cn
* epel: mirror.sjtu.edu.cn
* extras: mirrors.nju.edu.cn
* updates: mirrors.nju.edu.cn
base
...
弄克隆機的時候需要先將原始機器關(guān)機,然后創(chuàng)建克隆機:
原始機器關(guān)機:init 0
創(chuàng)建好克隆機之后重新連接上。
3、安裝網(wǎng)絡(luò)工具
[root@sc-mysql ~]# yum install net-tools -y
4、解壓壓縮包
tar -xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@sc-mysql opt]# tar -xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@sc-mysql opt]# ls
apache-zookeeper-3.6.3-bin kafka_2.12-2.8.1.tgz
apache-zookeeper-3.6.3-bin.tar.gz mysql-5.7.37-linux-glibc2.12-x86_64
kafka_2.12-2.8.1 mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
5、移動mysql解壓后的文件
移動mysql解壓后的文件到/usr/local下改名叫mysqlusr/local/mysql 是mysql的安裝目錄 --門店
[root@sc-mysql opt]#mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql
?6、新建組和用戶 mysql
mysql這個用戶的shell 是/bin/false 屬于mysql組。
useradd -r:是指創(chuàng)建系統(tǒng)用戶,也就是 UID 在 1~499 之間,供系統(tǒng)程序使用的用戶。由于系統(tǒng)用戶主要用于運行系統(tǒng)所需服務(wù)的權(quán)限配置,因此系統(tǒng)用戶的創(chuàng)建默認不會創(chuàng)建主目錄。
-g 組名:手工指定用戶的初始組。一般以和用戶名相同的組作為用戶的初始值,在創(chuàng)建用戶會默認建立初始組。一旦手動指定,系統(tǒng)將不會在創(chuàng)建此默認的初始組目錄。
[root@sc-mysql opt]# groupadd mysql
[root@sc-mysql opt]# useradd -r -g mysql -s /bin/false mysql
[root@sc-mysql opt]# ll -d /data/mysql
drwxr-xr-x 2 root root 6 7月 29 11:32 /data/mysql
7、關(guān)閉firewalld防火墻服務(wù),并且設(shè)置開機不要啟動
[root@sc-mysql opt]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@sc-mysql opt]# systemctl disable firewalld
8、臨時關(guān)閉selinux
[root@sc-mysql opt]# setenforce 0
setenforce: SELinux is disabled
也可以永久關(guān)閉selinux。
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config
[root@sc-mysql opt]# sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config
9、新建存放數(shù)據(jù)的目錄 為:/data/mysql
[root@sc-mysql opt]# mkdir /data/mysql -p
[root@sc-mysql opt]# ll -d /data/mysql
drwxr-xr-x 2 root root 6 7月 29 11:32 /data/mysql
10、修改/data/mysql目錄的權(quán)限
修改權(quán)限歸mysql用戶和mysql組所有,這樣mysql用戶啟動的mysql進程可以對這個文件夾進行讀寫了。只是允許mysql這個用戶和mysql組可以訪問,其他人都不能訪問。
[root@sc-mysql opt]#chown mysql:mysql /data/mysql/
[root@sc-mysql opt]#chmod 750 /data/mysql/
進入/usr/local/mysql/bin目錄。
[root@sc-mysql opt]#cd /usr/local/mysql/bin/
11、初始化mysql
--initialize :初始化? ---? basedir:基地 將生成的臨時密碼重定向到 &>passwd.txt
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql &>passwd.txt
?一定要記住自己的臨時密碼:密碼為最后一行。
[root@sc-mysql bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql
2022-07-29T03:36:45.934736Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
........
2022-07-29T03:36:47.113350Z 1 [Note] A temporary password is generated for root@localhost: ptogEfkPM8:f
?擴展知識:root@localhost: mysql里的超級用戶root只能在本機上登錄
比如sc@192.168.2.132 sc這個用戶只能在192.168.2.132 sc這臺服務(wù)器上登錄進入mysql
12、讓mysql支持ssl方式登錄的設(shè)置
./mysql_ssl_rsa_setup --datadir=/data/mysql/
[root@sc-mysql bin]# ./mysql_ssl_rsa_setup --datadir=/data/mysql/
13、修改PATH變量
進入mysql bin目錄的路徑。
臨時修改PATH變量的值:
export PATH=/usr/local/mysql/bin/:$PATH
[root@sc-mysql bin]# export PATH=/usr/local/mysql/bin/:$PATH
重新啟動linux系統(tǒng)后也生效,永久修改,讓root用戶也能使用。
[root@sc-mysql bin]# echo 'PATH=/usr/local/mysql/bin:$PATH' >>/root/.bashrc
[root@sc-mysql bin]# pwd
/usr/local/mysql/bin
?14、復制support-files里的mysql.server文件到/etc/init.d/目錄下叫mysqld
[root@sc-mysql bin]# cp ../support-files/mysql.server /etc/init.d/mysqld
修改/etc/init.d/mysqld腳本文件里的datadir目錄的值。
[root@sc-mysql bin]# vim /etc/init.d/mysqld #手動修改
[root@sc-mysql bin]# sed -i '70c datadir=/data/mysql' /etc/init.d/mysqld #直接命令修改
15、生成/etc/my.cnf配置文件
[root@sc-mysql bin]# cat >/etc/my.cnf <<EOF
> [mysqld_safe]
>
> [client]
> socket=/data/mysql/mysql.sock
>
> [mysqld]
> socket=/data/mysql/mysql.sock
> port = 3306
> open_files_limit = 8192
> innodb_buffer_pool_size = 512M
> character-set-server=utf8
>
> [mysql]
> auto-rehash
> prompt=\\u@\\d \\R:\\m mysql>
> EOF
?16、修改內(nèi)核的open file的數(shù)量
[root@sc-mysql bin]#ulimit -n 1000000
擴展:?ulimit -a 查看內(nèi)核的open file的數(shù)量。
[root@sc-mysql bin]# ulimit -a 查看內(nèi)核的open file的數(shù)量
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 3795
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 3795
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
?17、設(shè)置開機啟動的時候也配置生效
[root@sc-mysql bin]# echo "ulimit -n 1000000" >>/etc/rc.local
[root@sc-mysql bin]# chmod +x /etc/rc.d/rc.local
?18、將mysqld添加到linux系統(tǒng)里服務(wù)管理名單里
/sbin/chkconfig --add mysqld
[root@sc-mysql bin]# chkconfig --add mysqld
19、?設(shè)置mysqld服務(wù)開機啟動
/sbin/chkconfig mysqld on
[root@sc-mysql bin]# chkconfig mysqld on
#新式chkconfig mysql on
#chkconfig --list可以查看
[root@sc-mysql bin]# chkconfig --list
注:該輸出結(jié)果只顯示 SysV 服務(wù),并不包含
原生 systemd 服務(wù)。SysV 配置數(shù)據(jù)
可能被原生 systemd 配置覆蓋。
要列出 systemd 服務(wù),請執(zhí)行 'systemctl list-unit-files'。
查看在具體 target 啟用的服務(wù)請執(zhí)行
'systemctl list-dependencies [target]'。
mysqld 0:關(guān) 1:關(guān) 2:開 3:開 4:開 5:開 6:關(guān)
netconsole 0:關(guān) 1:關(guān) 2:關(guān) 3:關(guān) 4:關(guān) 5:關(guān) 6:關(guān)
network 0:關(guān) 1:關(guān) 2:開 3:開 4:開 5:開 6:關(guān)
?20、啟動mysqld進程
service mysqld start
[root@sc-mysql bin]# service mysqld start
Starting MySQL.Logging to '/data/mysql/sc-mysql.err'.
SUCCESS!
查看進程是否啟動:
[root@sc-mysql bin]# ps -ef|grep mysql
21、進入mysql,使用剛剛的臨時密碼
[root@sc-mysql bin]# mysql -uroot -p'ptogEfkPM8:f'
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 2
Server version: 5.7.37
22、進入數(shù)據(jù)之后修改密碼
set password='Sanchuang123#';
修改root用戶的密碼為Sanchuang123#
root@(none) 11:59 mysql>set password='Sanchuang123#';
Query OK, 0 rows affected (0.00 sec)
?檢驗上一步修改密碼是否成功,如果有輸出能看到mysql里的數(shù)據(jù)庫。
root@(none) 12:01 mysql>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
然后使用init 6 重新啟動機器,然后使用修改后的密碼進行登錄,如果成功登錄。那就說明密碼修改成功:
[root@sc-mysql ~]# mysql -uroot -p'Sanchuang123#'
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 2
Server version: 5.7.37 MySQL Community Server (GPL)
查看數(shù)據(jù)庫中的有哪些數(shù)據(jù)庫:
root@(none) 12:03 mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
如果出現(xiàn)這樣就說明安裝成功了。
如果覺得在命令行執(zhí)行命令安裝步驟比較多的話,可以通過編寫一個腳本來執(zhí)行安裝:文章來源:http://www.zghlxwxcb.cn/news/detail-489484.html
https://gitee.com/angel521/hyrz-student/tree/master/Linux%E8%84%9A%E6%9C%AC%E6%96%87%E4%BB%B6/%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2%E7%B1%BB%E8%84%9A%E6%9C%AC文章來源地址http://www.zghlxwxcb.cn/news/detail-489484.html
到了這里,關(guān)于mysql數(shù)據(jù)庫安裝教程(超級超級詳細)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!