2019-05-7笔记

Day47

课堂笔记

2019年5月7日

mysql安装和数据迁移


#1.创建用户

useradd mysql -s /sbin/nologin -M

id mysql

#2.创建目录上传软件

mkdir -p /server/tools/

cd /server/tools/

#wget -----


#3、解压安装

tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

mkdir -p /application

mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql-5.7.26

ln -s /application/mysql-5.7.26/  /application/mysql


#4、配置配置文件

rpm -e --nodeps mariadb-libs

cat >/etc/my.cnf<<EOF

[mysqld]

basedir = /application/mysql/

datadir = /application/mysql/data

socket = /tmp/mysql.sock

server_id = 1

port = 3306

log_error = /application/mysql/data/oldboy_mysql.err


[mysql]

socket = /tmp/mysql.sock

prompt = oldboy [\\d]>

EOF


#5.初始化数据库

rpm -qa mariadb-libs

yum install libaio-devel -y


mkdir -p /application/mysql/data

chown -R mysql.mysql /application/mysql/


/application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data


#6、配置启动

cat >/etc/systemd/system/mysqld.service<<EOF

[Unit]

Description=MySQL Server by oldboy

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE = 5000

EOF

systemctl start mysqld

systemctl enable mysqld

netstat -lntup|grep mysql


#7.登录测试

echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile

. /etc/profile

mysql

quit




#数据库迁移:

从单机LNMP迁移到DB01独立的mysql


web02:

备份:

[root@web02 ~]# mysqldump -uroot -poldboy123 -A -B|gzip >/tmp/web02_db.sql.gz

mysqldump: [Warning] Using a password on the command line interface can be insecure.


拷贝到异机:

[root@web02 ~]# scp /tmp/web02_db.sql.gz 10.0.0.51:/tmp


systemctl stop mysqld

systemctl disable mysqld

lsof -i :3306


web02:

[root@web02 ~]# cd /application/nginx/html/blog/

[root@web02 /application/nginx/html/blog]# vim wp-config.php

define( 'DB_NAME', 'wordpress' );


/** MySQL database username */

define( 'DB_USER', 'wordpress' );


/** MySQL database password */

define( 'DB_PASSWORD', 'oldboy123' );


/** MySQL hostname */

define( 'DB_HOST', '172.16.1.51' );




db01:

lsof -i :3306


[root@db01 ~]# cd /tmp

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

[root@db01 /tmp]# mysql </tmp/web02_db.sql


grant all privileges on wordpress.* to wordpress@'172.16.1.%' identified by 'oldboy123';

flush privileges;

select user,authentication_string,host from mysql.user;

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容