Cara memasang mysql di luar talian dalam centos: 1. Muat naik semua kebergantungan dalam lib ke linux dan pasangkannya dengan perintah yum 2. Unzip MySQL dan salin fail ke direktori yang anda ingin pasang; .cnf fail konfigurasi; 4. Salin skrip permulaan ke direktori sumber dan ubah suai skrip permulaan.
Persekitaran pengendalian tutorial ini: sistem centOS 7, MySQL versi 5.6, komputer Dell G3.
Bagaimana untuk memasang mysql di luar talian dalam centos?
centOS 7 pemasangan luar talian MySQL 5.6
Sediakan persekitaran
1 ( Berikut ialah pemasangan minimum centOS 7)
2 Fail pemasangan nginx (mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz telah diletakkan di pautan di bawah, sila muat turunnya. sendiri atau buat sendiri Pergi ke laman web rasmi untuk memuat turun versi terkini)
3 pakej pergantungan nginx (pada masa ini diletakkan dalam direktori lib, anda boleh memuat turunnya sendiri)
Pada masa ini semua pakej dan kebergantungan yang diperlukan untuk pemasangan tersedia Pergi ke alamat berikut untuk memuat turun sendiri perisian yang sepadan
https://gitee.com/livekeys/linux-offline-installation-software
Semak sama ada terdapat mariadb sebelum ini , padamkannya jika ada, dan padamkan fail konfigurasi sebelumnya /etc/my.cnf
[root@localhost ~]# rpm -qa | grep mariadb* mariadb-libs-5.5.56-2.el7.x86_64 [root@localhost ~]# rpm -e mariadb-libs --nodeps [root@localhost ~]# rpm -qa | grep mariadb* [root@localhost ~]# rm -f /etc/my.cnf [root@localhost ~]#
Muat naik semua tanggungan dalam lib ke linux dan pasangkannya dengan arahan
[root@localhost lib]# yum -y localinstall *.rpm
1. mysql sebagai direktori pemasangan)
[root@localhost mysql_install]# tar -xzvf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz [root@localhost mysql_install]# ls lib mysql-5.6.51-linux-glibc2.12-x86_64 mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz [root@localhost mysql_install]# cp -R mysql-5.6.51-linux-glibc2.12-x86_64 /opt/mysql [root@localhost mysql_install]# cd /opt/mysql [root@localhost mysql]# ls bin data docs include lib LICENSE man mysql-test README scripts share sql-bench support-files
2 Cipta kumpulan mysql dan pengguna mysql baharu, dan gantikan direktori mysql dengan kumpulan pengguna mysql
[root@localhost mysql]# groupadd mysql [root@localhost mysql]# useradd -g mysql mysql [root@localhost mysql]# cd .. [root@localhost opt]# ls mysql [root@localhost opt]# chown -R mysql:mysql mysql [root@localhost opt]# ll total 0 drwxr-xr-x. 13 mysql mysql 191 Mar 23 01:42 mysql [root@localhost opt]# cd mysql [root@localhost mysql]# ll total 224 drwxr-xr-x. 2 mysql mysql 4096 Mar 23 01:42 bin drwxr-xr-x. 3 mysql mysql 18 Mar 23 01:42 data drwxr-xr-x. 2 mysql mysql 55 Mar 23 01:42 docs drwxr-xr-x. 3 mysql mysql 4096 Mar 23 01:42 include drwxr-xr-x. 3 mysql mysql 4096 Mar 23 01:42 lib -rw-r--r--. 1 mysql mysql 200256 Mar 23 01:42 LICENSE drwxr-xr-x. 4 mysql mysql 30 Mar 23 01:42 man drwxr-xr-x. 10 mysql mysql 4096 Mar 23 01:42 mysql-test -rw-r--r--. 1 mysql mysql 566 Mar 23 01:42 README drwxr-xr-x. 2 mysql mysql 30 Mar 23 01:42 scripts drwxr-xr-x. 28 mysql mysql 4096 Mar 23 01:42 share drwxr-xr-x. 4 mysql mysql 4096 Mar 23 01:42 sql-bench drwxr-xr-x. 2 mysql mysql 136 Mar 23 01:42 support-files
3 Direktori /var/lib/mysql untuk menyimpan mysq.sock (juga Anda boleh mencipta direktori lain), dan menukar kumpulan yang menjadi milik direktori myql
[root@localhost mysql]# mkdir /var/lib/mysql [root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql [root@localhost mysql]# ls -al /var/lib/mysql total 4 drwxr-xr-x. 2 mysql mysql 6 Mar 23 01:51 . drwxr-xr-x. 26 root root 4096 Mar 23 01:51 ..
4 Masukkan direktori pemasangan mysql dan mulakan mysql
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data Installing MySQL system tables...2022-03-23 01:53:51 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-03-23 01:53:51 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2022-03-23 01:53:51 0 [Note] /opt/mysql/bin/mysqld (mysqld 5.6.51) starting as process 13346 ... 2022-03-23 01:53:51 13346 [Note] InnoDB: Using atomics to ref count buffer pool pages 2022-03-23 01:53:51 13346 [Note] InnoDB: The InnoDB memory heap is disabled 2022-03-23 01:53:51 13346 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2022-03-23 01:53:51 13346 [Note] InnoDB: Memory barrier is not used 2022-03-23 01:53:51 13346 [Note] InnoDB: Compressed tables use zlib 1.2.11 2022-03-23 01:53:51 13346 [Note] InnoDB: Using Linux native AIO 2022-03-23 01:53:51 13346 [Note] InnoDB: Using CPU crc32 instructions 2022-03-23 01:53:51 13346 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2022-03-23 01:53:51 13346 [Note] InnoDB: Completed initialization of buffer pool 2022-03-23 01:53:51 13346 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2022-03-23 01:53:51 13346 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2022-03-23 01:53:51 13346 [Note] InnoDB: Database physically writes the file full: wait... 2022-03-23 01:53:51 13346 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2022-03-23 01:53:51 13346 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2022-03-23 01:53:51 13346 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2022-03-23 01:53:51 13346 [Warning] InnoDB: New log files created, LSN=45781 2022-03-23 01:53:51 13346 [Note] InnoDB: Doublewrite buffer not found: creating new 2022-03-23 01:53:51 13346 [Note] InnoDB: Doublewrite buffer created 2022-03-23 01:53:51 13346 [Note] InnoDB: 128 rollback segment(s) are active. 2022-03-23 01:53:51 13346 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-03-23 01:53:51 13346 [Note] InnoDB: Foreign key constraint system tables created 2022-03-23 01:53:51 13346 [Note] InnoDB: Creating tablespace and datafile system tables. 2022-03-23 01:53:51 13346 [Note] InnoDB: Tablespace and datafile system tables created. 2022-03-23 01:53:51 13346 [Note] InnoDB: Waiting for purge to start 2022-03-23 01:53:51 13346 [Note] InnoDB: 5.6.51 started; log sequence number 0 2022-03-23 01:53:51 13346 [Note] RSA private key file not found: /opt/mysql/data//private_key.pem. Some authentication plugins will not work. 2022-03-23 01:53:51 13346 [Note] RSA public key file not found: /opt/mysql/data//public_key.pem. Some authentication plugins will not work. 2022-03-23 01:53:51 13346 [Note] Binlog end 2022-03-23 01:53:51 13346 [Note] InnoDB: FTS optimize thread exiting. 2022-03-23 01:53:51 13346 [Note] InnoDB: Starting shutdown... 2022-03-23 01:53:53 13346 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK Filling help tables...2022-03-23 01:53:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-03-23 01:53:53 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2022-03-23 01:53:53 0 [Note] /opt/mysql/bin/mysqld (mysqld 5.6.51) starting as process 13368 ... 2022-03-23 01:53:53 13368 [Note] InnoDB: Using atomics to ref count buffer pool pages 2022-03-23 01:53:53 13368 [Note] InnoDB: The InnoDB memory heap is disabled 2022-03-23 01:53:53 13368 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2022-03-23 01:53:53 13368 [Note] InnoDB: Memory barrier is not used 2022-03-23 01:53:53 13368 [Note] InnoDB: Compressed tables use zlib 1.2.11 2022-03-23 01:53:53 13368 [Note] InnoDB: Using Linux native AIO 2022-03-23 01:53:53 13368 [Note] InnoDB: Using CPU crc32 instructions 2022-03-23 01:53:53 13368 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2022-03-23 01:53:53 13368 [Note] InnoDB: Completed initialization of buffer pool 2022-03-23 01:53:53 13368 [Note] InnoDB: Highest supported file format is Barracuda. 2022-03-23 01:53:53 13368 [Note] InnoDB: 128 rollback segment(s) are active. 2022-03-23 01:53:53 13368 [Note] InnoDB: Waiting for purge to start 2022-03-23 01:53:53 13368 [Note] InnoDB: 5.6.51 started; log sequence number 1625977 2022-03-23 01:53:53 13368 [Note] RSA private key file not found: /opt/mysql/data//private_key.pem. Some authentication plugins will not work. 2022-03-23 01:53:53 13368 [Note] RSA public key file not found: /opt/mysql/data//public_key.pem. Some authentication plugins will not work. 2022-03-23 01:53:53 13368 [Note] Binlog end 2022-03-23 01:53:53 13368 [Note] InnoDB: FTS optimize thread exiting. 2022-03-23 01:53:53 13368 [Note] InnoDB: Starting shutdown... 2022-03-23 01:53:55 13368 [Note] InnoDB: Shutdown completed; log sequence number 1625987 OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /opt/mysql/bin/mysqladmin -u root password 'new-password' /opt/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run: /opt/mysql/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; /opt/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /opt/mysql/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings
4. Salin dan ubah suai Fail konfigurasi
[root@localhost mysql]# cp ./support-files/my-default.cnf /etc/my.cnf [root@localhost mysql]# chown mysql:mysql /etc/my.cnf [root@localhost mysql]# chmod 644 /etc/my.cnf
kandungan fail konfigurasi my.cnf adalah seperti berikut: (Ubah suai konfigurasi lain mengikut anda perlukan di sini)
Perhatikan perkara berikut:
socket
Tulis direktori yang kami buat dalam langkah ketiga di atas basedir
ialah direktori pemasangan mysql datadir
ialah direktori data (di sini Ia adalah direktori data di bawah direktori pemasangan mysql) [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 socket=/var/lib/mysql/mysql.sock [mysqld] skip-name-resolve #设置 13306 端口 port = 13306 socket=/var/lib/mysql/mysql.sock # 设置mysql的安装目录 basedir=/opt/mysql # 设置mysql数据库的数据的存放目录 datadir=/opt/mysql/data # 允许最大连接数 max_connections=200 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB lower_case_table_name=1 max_allowed_packet=16M
5 ke direktori sumber
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld [root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld [root@localhost mysql]# chown mysql:mysql /etc/rc.d/init.d/mysqld
6 Ubah suai skrip permulaan
[root@localhost mysql]# vim /etc/rc.d/init.d/mysqld
Nota: Kerana saya tidak memasang mysql dalam direktori /usr/local/mysql, saya perlu mengubah suai dua nilai berikut dalam fail permulaan
basedir=/opt/mysql datadir=/opt/mysql/data
7. Tambahkan perkhidmatan mysqld ke dalam perkhidmatan sistem
[root@localhost mysql]# chkconfig --add mysqld [root@localhost mysql]# chkconfig --list mysqld Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
8 perkhidmatan mysql (status Aktif aktif (berjalan), yang bermaksud permulaan berjaya)
[root@localhost mysql]# systemctl start mysql [root@localhost mysql]# systemctl status mysql ● mysqld.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: active (running) since Wed 2022-03-23 02:11:17 EDT; 5s ago Docs: man:systemd-sysv-generator(8) Process: 13452 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS) CGroup: /system.slice/mysqld.service ├─13463 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/opt/mysql/data/lo... └─13688 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mys... Mar 23 02:11:16 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL... Mar 23 02:11:16 localhost.localdomain mysqld[13452]: Starting MySQL.Logging to '/opt/mysql/data/localhost....r'. Mar 23 02:11:17 localhost.localdomain mysqld[13452]: SUCCESS! Mar 23 02:11:17 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL. Hint: Some lines were ellipsized, use -l to show in full.
9 Konfigurasikan klien mysql kepada pembolehubah persekitaran dan buat konfigurasi berkuat kuasa
[root@localhost mysql]# vim /etc/profile # 在末尾增加以下两行 export MYSQL_HOME=/opt/mysql export PATH=$MYSQL_HOME/bin:$PATH [root@localhost mysql]# source /etc/profile
10. Uji sama ada ia boleh menyambung ke mysql
Nota: Tiada kata laluan diperlukan untuk log masuk pertama, hanya tekan Enter
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.51 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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>
11 kata laluan akaun root
kepada P@ssw0rd
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set password=password('P@ssw0rd') where user='root' and host='localhost'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
12 🎜>
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> grant all privileges on *.* to 'root'@'%' identified by 'P@ssw0rd' with grant option; Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# systemctl restart mysql [root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.51 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql>
Jika terdapat sebarang kesilapan, sila tinggalkan mesej untuk membetulkan saya, terima kasih! Pembelajaran yang disyorkan: "
Tutorial Video MySQL"
Atas ialah kandungan terperinci Bagaimana untuk memasang mysql luar talian pada centos. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!