1. 程式人生 > >mysql二進位制安裝和資料備份

mysql二進位制安裝和資料備份

一、mysql二進位制的安裝

1.從ftp上傳並解壓檔案

建立使用者和使用者組

[[email protected][[email protected] ~]# groupadd -r mysql
[[email protected] ~]# useradd -M -s /sbin/nologin -g mysql mysql
[[email protected] ~]# tar xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[[email protected] ~]# cd /usr/local/
[
[email protected]
local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql

修改目錄屬組屬主

[[email protected] local]# chown -R mysql.mysql /usr/local/mysql

新增環境變數

[[email protected] ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH'>/etc/profile.d/mysql.sh
[[email protected] ~]# . /etc/profile.d/mysql.sh
[
[email protected]
~]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

建立資料庫存放目錄

[[email protected] ~]# mkdir /opt/data
[[email protected] ~]# chown -R mysql.mysql /opt/data/
[[email protected] ~]#/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/

生成配置檔案

[[email protected] ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[[email protected] ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

配置啟動服務指令碼

[[email protected] ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
 [[email protected] ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[[email protected] ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

啟動mysql服務

[[email protected] ~]# /etc/init.d/mysqld start
[[email protected] ~]# ps -ef|grep mysql

使用臨時密碼修改為新密碼

[[email protected] ~]# mysql -uroot -p
Enter password: 
mysql> set password = password('qinyong123!') ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

建立倉庫和表

mysql> create database qinyong;
Query OK, 1 row affected (0.01 sec)
mysql> use qinyong;
Database changed
mysql> create table student(id int(11)NOT NULL,name char(100)NOT NULL,age tinyint NULL);
Query OK, 0 rows affected (0.02 sec)
mysql> create database qin;
Query OK, 1 row affected (0.00 sec)
mysql> use qin;
Database changed
mysql> create table student(id int(11)NOT NULL,name char(100)NOT NULL,age tinyint NULL);
Query OK, 0 rows affected (0.06 sec)

mysqldump -uroot -p -h192.168.100.148 --all-databases > all-0925.sql