MySQL经验总结

RPM安装

安装官网YUM源
sudo yum install mysql80-community-release-el7-11.noarch

官网安装
sudo yum install mysql80-community-release-el7-11.noarch.rpm

查看默认密码
sudo grep password /var/log/mysqld.log 

修改密码
sudo mysqladmin -uroot -p'xxxxxx' password 'XXxxx'

登录查看
mysql -uroot -p'XXxxx'
show databases;

编译安装

安装编译软件
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison

编译
cd mysql-8.0
cmake \

安装
cd mysql-8.0
make -j 2 && make install

创建用户
useradd mysql -s /sbin/nologin
chown -R mysql.mysql /usr/local/mysql

创建配置文件
vi /etc/my.cnf

添加环境变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile

初始化
mysql --initialize-insecure --user=mysql --baseurl=/usr/local/mysql --datadir=/usr/loacl/mysql/data

创建systemd进程
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
systemctl daemon-reload
systemctl enable mysqld --now
 

自建YUM

安装FTP
yum install -y vsftpd
mkdir /var/ftp/mysql8/

安装官网YUM源
yum install -y mysql80-community-release-el7-11.noarch

下载安装包
yum install -y --downloadonly mysql-community-server
cp -rf /var/cache/yum/x86_64/7/mysql80-community/packages/* /var/ftp/mysql8/

创建依赖关系
cd /var/ftp/mysql8/
yum provides createrepo
yum install -y createrepo_c
createrepo /var/ftp/mysql8/ 

启动FTP
vi /etc/vsftpd/vsftpd.conf
 anonymous_enable=YES
systemctl start vsftpd



客户端配置
vi /etc/yum.repo.d/mysql.repo
[mysql8]
name=ftp
baseurl=ftp://x.x.x.x/mysql8
gpgcheck=0
enabled=1

密码破解

[root@node1 ~]# echo 'skip-grant-tables' >>/etc/my.cnf
[root@node1 ~]# systemctl restart mysqld
[root@node1 ~]# mysql -uroot
mysql> update mysql.user set authentication_string='' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update mysql.user set authentication_string='' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> \q
Bye


[root@node1 ~]# sed -i 's/^skip.*//g' /etc/my.cnf
[root@node1 ~]# mysqladmin -uroot -p  password 'JKzone@123'
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

日志管理

Error log、查询日志、二进制日志、中继日志、slow log、DDL log


一、Error log
log-error=


二、二进制日志
datadir=

xxx-bin.00xxx      <<---该二进制文件,刷新后自动增加
xxx-bin.index      <<---所有二进制文件

[root@node1 ~]# echo -e "log_bin \n server-id=1" >> /etc/my.cnf       <<---开启
[root@node1 ~]# systemctl restart mysqld
[root@node1 mysql]# mysqlbinlog -v /var/lib/mysql/node1-bin.000002   <<---查看



三、slow log
/var/lib/mysql/node1-slow.log 

[root@node1 mysql]# echo -e 'slow_query_log=1 \n long_query_time=3' >>/etc/my.cnf  <<---开启
[root@node1 mysql]# systemctl restart mysqld



四、查询日志
/var/lib/mysql/node1.log 

[root@node1 mysql]# echo 'general_log=1' >> /etc/my.cnf      <<---开启
[root@node1 mysql]# systemctl restart mysqld



你可能感兴趣的:(数据库,mysql,数据库)