数据库

MySQL 数据库二进制部署

2021-06-16  本文已影响0人  Joening

部署与配置:

rpm -e --nodeps mariadb-libs
useradd -M -s /sbin/nologin mysql
tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.7.31-linux-glibc2.12-x86_64/ mysql
mkdir /data/mysql/data -p
chown -R mysql.mysql /usr/local/mysql/ /data
ln -s /usr/local/mysql/bin/* /usr/local/bin/
cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld 
chkconfig --add mysqld
vim /etc/my.cnf
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data/
yum -y install libaio-devel
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data/
systemctl start mysqld
netstat -lantup |grep mysqld 
ps -ef |grep mysql
ss -lnt
lsof -i :3306
mysqladmin -uroot -p password 123
mysql -uroot -p123 -S /tmp/mysql.sock
mysql -uroot -p123 -h10.0.0.51 -P3306     #TCP/IP方式连接

[root@db01/usr/local]#cat /etc/my.cnf 
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/data/
port=3306
socket=/tmp/mysql.sock
server_id=3306
log_bin=/data/mysql/data/mysql-bin
log_error=/data/mysql/data/mysql.log
[mysql]
socket=/tmp/mysql.sock

忘记密码操作步骤:

systemctl stop mysqld
mysqld_safe --skip-grant-tables --skip-networking & 
mysql
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> 
mysql> alter user root@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> shutdown;
Query OK, 0 rows affected (0.00 sec)
systemctl start mysqld 

启动数据库的三种方式

 mysqld &  程序启动
mysqld_safe &  脚本启动
/etc/init.d/mysqld && systemctl start mysqld 正常启动 mysqld 也是一个脚本

完整版

[root@shell~]#rpm -qa |grep mariadb | xargs rpm -e --nodeps 
[root@shell~]#useradd -M -s /sbin/nologin mysql
[root@shell~]#id mysql
[root@shell~]#tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@shell~]#hostnamectl set-hostname db01
[root@db01/usr/local]#ln -s /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@db01/usr/local]#mkdir -p /data/mysql/data/ /data/binlog/ /data/mysql/logs
[root@db01/usr/local]#chown -R mysql.mysql /usr/local/mysql /data/
[root@db01/usr/local]#vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH                                                                                                                       
[root@db01/usr/local]#source /etc/profile

[root@db01/usr/local]#cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@db01/usr/local]#chmod +x /etc/init.d/mysqld 
[root@db01/usr/local]#chkconfig --add mysqld
[root@db01/usr/local]#cat >> /etc/my.cnf << eof
> [mysqld]
> user=mysql
> basedir=/usr/local/mysql
> datadir=/data/mysql/data/
> port=3306
> socket=/tmp/mysql.sock
> server_id=3306
> log_bin=/data/binlog/mysql-bin
> log_error=/data/mysql/logs/mysql.log
> [mysql]
> socket=/tmp/mysql.sock
> [client]
> socket=/tmp/mysql.sock
> eof

[root@db01/usr/local]#mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data/ 
[root@db01/usr/local]#yum -y install libaio-devel  
[root@db01/data/mysql/data]#/etc/init.d/mysqld start
[root@db01/data/mysql/data]#ss -lnt|grep 3306
LISTEN     0      80          :::3306                    :::*
[root@db01/data/mysql/data]#netstat -lantup |grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      16885/mysqld
上一篇下一篇

猜你喜欢

热点阅读