Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Separation of LNMP components

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Environment

[root@db01 ~] # cat / etc/redhat-release

CentOS release 6.7 (Final)

[root@db01 ~] # uname-r

2.6.32-573.el6.x86_64

[root@db01] # uname-m

X86_64

Create a software download directory

[root@db01 ~] # mkdir / home/oldboy/tools

Create a software installation directory

[root@db01 ~] # mkdir / application/

Download upload command

[root@db01 ~] # yum install-y lrzsz

Upload MySQL installation package

[root@db01 ~] # cd / home/oldboy/tools/

[root@db01 tools] # rz-y

(download the compressed package of MySQL5.5.49 in advance)

View

[root@db01 tools] # ls-lh

Total 178M

-rw-r--r-- 1 root root 178m May 16 23:19 mysql-5.5.49-linux2.6-x86_64.tar.gz

Create a mysql user

[root@db01 tools] # useradd-s / sbin/nologin mysql-M

Check

[root@db01 tools] # id mysql

Uid=501 (mysql) gid=501 (mysql) groups=501 (mysql)

Decompression

[root@db01 tools] # tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz

Move and rename

[root@db01 tools] # mv mysql-5.5.49-linux2.6-x86_64 / application/mysql-5.5.49

Create a soft link

[root@db01 tools] # ln-s / application/mysql-5.5.49/ / application/mysql

Check

[root@db01 tools] # ls / application/mysql

Bin docs lib README sql-bench

COPYING include man scripts support-files

Data INSTALL-BINARY mysql-test share

Change to the MySQL directory

[root@db01 tools] # cd / application/mysql

Authorization

[root@db01 mysql] # chown-R mysql.mysql / application/mysql/

Initialization

[root@db01 mysql] # / scripts/mysql_install_db-- basedir=/application/mysql/-- datadir=/application/mysql/data/

[root@db01 mysql] # ll-ld / tmp/

Drwxrwxrwt. 4 root root 4096 May 18 01:12 / tmp/

[root@db01 mysql] # ll data/

Total 12

Drwx- 2 mysql root 4096 May 18 01:12 mysql

Drwx- 2 mysql mysql 4096 May 18 01:12 performance_schema

Drwxr-xr-x 2 mysql mysql 4096 May 18 01:07 test

Modify the startup script file path

[root@db01 mysql] # cd bin/

[root@db01 bin] # cp mysqld_safe {, .ori}

Replace, because the default directory of binaries is not under our upload and release software / application/

[root@db01 bin] # sed-I's engine mysqld_safe usr mysqld_safe

Copy to / etc

[root@db01 mysql] # cd.. /

[root@db01 mysql] #\ cp support-files/my-small.cnf / etc/my.cnf

[root@db01 mysql] # / application/mysql/bin/mysqld_safe-- user=mysql & # (it takes a long time, estimated one minute)

[root@db01 mysql] # lsof-I: 3306

[root@db01 mysql] # / application/mysql/bin/mysql

Set global variables

[root@db01 mysql] # echo 'export PATH=/application/mysql/bin:$PATH' > > / etc/profile

[root@db01 mysql] # tail-1 / etc/profile

Export PATH=/application/mysql/bin:$PATH

[root@db01 mysql] #. / etc/profile

[root@db01 mysql] # echo $PATH

/ application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Set up the MySQL startup script

[root@db01 mysql] # cd support-files/

[root@db01 support-files] # cp mysql.server {, .ori}

[root@db01 support-files] # cd..

[root@db01 mysql] # cp support-files/mysql.server / etc/init.d/mysqld

[root@db01 mysql] # chmod + x / etc/init.d/mysqld

[root@db01 mysql] # sed-I's tracking engine usr _ use _ application _ etc/init.d/mysqld

Set MySQL Boot self-boot

[root@db01 mysql] # chkconfig-- add mysqld

[root@db01 mysql] # chkconfig mysqld on

[root@db01 mysql] # chkconfig-- list mysqld

Mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Tip: you can also put the startup command / etc/init.d/mysqld start into / etc/rc.local.

Migrate the wordpress database to the back-end database or the database migration

1. Operate on 10.0.0.8

1. Export a wordpress database in a web10.0.0.8 database

[root@web01 ~] # mysqldump-uroot-poldboy123 wordpress-B | gzip > bak.sql.gz

[root@web01 ~] # ls

Anaconda-ks.cfg bak.sql.gz install.log install.log.syslog nginx-1.6.3.tar.gz

[root@web01 ~] #

two。 Transfer the script of the data backup to the file system of the background database 10.0.0.51 to restore and add to the database

[root@web01 ~] # scp bak.sql.gz root@10.0.0.51:/tmp

The authenticity of host '10.0.0.51 (10.0.0.51)' can't be established.

RSA key fingerprint is 61:c1:8c:77:39:33:91:47:5c:4c:b5:0f:5a:aa:7d:be.

Are you sure you want to continue connecting (yes/no)? Yes

Warning: Permanently added '10.0.0.51' (RSA) to the list of known hosts.

Root@10.0.0.51's password:

Bak.sql.gz 100% 121KB 121.2KB/s 00:00

[root@web01 ~] #

③ changes the configuration file that accesses the database

[root@web01 blog] # cd / application/nginx/html/blog/

[root@web01 blog] # vim wp-config.php

Define ('DB_HOST',' 172.16.1.51')

two。 Operate on 10.0.0.51

Decompression

[root@db01 mysql] # cd / tmp/

[root@db01 tmp] # gzip-d bak.sql.gz

Import data

[root@db01 tmp] # mysql-uroot-poldboy123 grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456'

Query OK, 0 rows affected (0.00 sec)

Mysql >

3 close the database of 10.0.0.8

[root@web01 blog] # / etc/init.d/mysqld stop

[root@web01 blog] # chkconfig mysqld off

[root@web01 blog] # chkconfig-- list mysqld

Mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@web01 blog] #

4 Test:

Http://blog.etiantian.org/wp-admin/edit.php

Publish an article on the web interface, then go to the 172.16.1.51 server to test the data

Mysql > select * from old_posts\ G

The separation of wordpress images, separating the pictures to NFS

1. Establish a NFS mount point and authorize

[root@nfs01 ~] # cat / etc/exports

/ data/upload 172.16.1.0 Compact 24 (rw,sync,all_squash,anonuid=500,anongid=500)

[root@nfs01] # mkdir-p / data/upload

[root@nfs01] # useradd-u 506-s / sbin/nologin www-M

[root@nfs01 ~] # id www

Uid=506 (www) gid=506 (www) groups=506 (www)

[root@nfs01] # chown-R www.www / data/upload

[root@nfs01 ~] #

two。 The data of this local machine prevents errors in the middle.

[root@web01 tmp] # cd / application/nginx/html/blog/wp-content/uploads/

[root@web01 uploads] # pwd

/ application/nginx/html/blog/wp-content/uploads

[root@web01 uploads] # cp-a 2016 / tmp/

3. Local mount

[root@web01 uploads] # mount-t nfs 172.16.1.31:/data/upload / application/nginx/html/blog/wp-content/uploads

[root@web01 uploads] # df-h / application/nginx/html/blog/wp-content/uploads

Filesystem Size Used Avail Use% Mounted on

172.16.1.31:/data/upload

6.9g 1.5g 5.1g 22% / application/nginx-1.6.3/html/blog/wp-content/uploads

[root@web01 uploads] #

4. Migrate the original data back

[root@web01 tmp] #\ cp-a / tmp/2016 / application/nginx/html/blog/wp-content/uploads/

Reflection: the NFS shared directory must have the same permissions as the users of the nginx directory. In the early days, application/nginx/ granted nginx permission to this.

Otherwise, you cannot write.

Reflection on wordpress

The permissions of the 1.nginx storage directory should be the same as those allowed to mount remotely by NFS.

two。 All services should be booted up.

3. The first step to migrate data is to back up the data.

The boot mount of the 4.NFS mount side should be placed in / etc/rc.lcoal, not in / etc/fstab

1. Log into the database

[root@web01 data] # mysql-uroot-p

two。 Change the password of a known user

[root@web01 ~] # mysqladmin-uroot-p123456 password "oldboy"

3. Initialize the password for root

[root@web01 ~] # mysqladmin-uroot password "123456"

4. View the database

Mysql > show databses

5. Using the database

Mysql > use mysql

Database changed

Mysql >

6. View the tables in the database

Mysql > show tables

7. View the structure of the data table

Mysql > describe user

8. Find fields from the table (the fields queried here are not case-sensitive)

Mysql > select Host,User from user; # look up the table directly

Mysql > select host,user from mysql.user; # which table from which library

9. Delete data from the library (users in the use database)

Mysql > drop user "sanlang" @ "10.0.0.8"

Or:

Mysql > delete from mysql.user where user= "sanlang" and host= "110.0.0.8"

10. View current users

Mysql > select user ()

11. View the current database

Mysql > select database ()

twelve。 Finish processing the commands to be executed by the user

Mysql > flush privileges

13. Export database

[root@web01] # mysqldump-uroot-poldboy123 wordexpress-B | gzip > bak.sql.gz

14. Import the database script

[root@web01] # mysql-uroot-poldboy123

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report