set global read_only=1;–针对普通MySQL数据库用户设置为只读 set global super_read_only=1;–针对super类MySQL数据库用户设置为只读,比如root用户 //flush tables with read lock;–设定全局锁,如果只是需要只读,并不需要加锁 show global variables like “%read_only%”;–查询全局变量表数据情况
—-2022-01-30T00:14:24.872326+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: bDB,fVSmt2/U
修改配置
默认/etc/my.cnf
1 2 3 4
url=/opt/mysql sed -n "/^basedir=/s#=#==$url#"p ./mysql.server sed -n "/^datadir=/s#=#=$url/data#"p ./mysql.server sed -n "s#conf=.*#conf=$url/my.cnf#"p ./mysql.server
开机启动
1 2 3 4 5
sudo cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql 设置为开机自动运行 sudo update-rc.d mysql defaults 设置为取消开机自动运行 sudo update-rc.d -f mysql remove
##### 临时密码登录,执行语句提示 You must reset your password using ALTER USER statement before executing this statement. --- alter user user() identified by "123456"; ##密码字符串双引号
---低于版本8---SET PASSWORD FOR root@localhost = '123456'; ---版本8以上---ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
##用户密码过期时间250天 ALTER USER ‘cs’@‘localhost' PASSWORD EXPIRE INTERVAL 250 DAY; ###禁用过期 --恢复默认策略 PASSWORD EXPIRE DEFAULT---- ALTER USER 'cs'@'localhost' PASSWORD EXPIRE NEVER;
###密码过期的策略 show variables like 'default_password_lifetime'; ---设置密码永不过期,需要把default_password_lifetime修改为 0 ---set global default_password_lifetime = 0;
CREATE USER 'cs'@'localhost' IDENTIFIED BY '123456';
E:\MySQL\MySQL Server 5.7\bin>mysqld install MySQL --defaults-file="E:\MySQL\MySQL Server 5.7\my.ini"
install/Remove of the Service Denied!
1
bin>mysqld --initialize --user=mysql --console
启动服务
1
net start MySQL
删除
1
sc delete MySQL
other
Permission denied
检查目录所属用户mysql
rm /tmp/mysql*
1 2 3 4 5 6
❯ ls -l /tmp/mysql* -rw-r----- 1 mysql mysql 6 6月 4 21:08 /tmp/mysqld.pid srwxrwxrwx 1 mysql mysql 0 6月 4 21:08 /tmp/mysql.sock -rw------- 1 mysql mysql 6 6月 4 21:08 /tmp/mysql.sock.lock srwxrwxrwx 1 mysql mysql 0 6月 4 21:08 /tmp/mysqlx.sock -rw------- 1 mysql mysql 6 6月 4 21:08 /tmp/mysqlx.sock.lock
╰─❯ 2023-06-04T11:50:10.086155Z 0 [System] [MY-010116] [Server] /opt/mysql/bin/mysqld (mysqld 8.0.32) starting as process 5008 2023-06-04T11:50:10.089112Z 0 [Warning] [MY-010122] [Server] One can only use the –user switch if running as root 2023-06-04T11:50:10.094189Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2023-06-04T11:50:10.195060Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2023-06-04T11:50:10.385679Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2023-06-04T11:50:10.385746Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2023-06-04T11:50:10.386292Z 0 [ERROR] [MY-010262] [Server] Can’t start server: Bind on TCP/IP port: Address already in use 2023-06-04T11:50:10.386343Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3306 ? 2023-06-04T11:50:10.386383Z 0 [ERROR] [MY-010119] [Server] Aborting 2023-06-04T11:50:11.974477Z 0 [System] [MY-010910] [Server] /opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
sed -i "s@http://\(deb\|security\).debian.org@https://mirrors.aliyun.com@g" /etc/apt/sources.list
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib deb https://mirrors.aliyun.com/debian-security/ bullseye-security main deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
g 表示行内全面替换。 global 全局 p 表示打印行。 P 打印模板第一行 r 读文件 -n :使用安静(silent)模式。在一般 sed 的用法中,所有来自 STDIN 的数据一般都会被列出到终端上。但如果加上 -n 参数后,则只有经过sed 特殊处理的那一行(或者动作)才会被列出来。 -e :直接在命令列模式上进行 sed 的动作编辑; -f :直接将 sed 的动作写在一个文件内, -f filename 则可以运行 filename 内的 sed 动作; -r :sed 的动作支持的是延伸型正规表示法的语法。(默认是基础正规表示法语法) -i :直接修改读取的文件内容,而不是输出到终端 w 表示把行写入一个文件。 x 表示互换模板块中的文本和缓冲区中的文本。 y 表示把一个字符翻译为另外的字符(但是不用于正则表达式) \1 子串匹配标记 & 已匹配字符串标记元字符集 ^ 匹配行开始,如:/^sed/匹配所有以sed开头的行。 $ 匹配行结束,如:/sed$/匹配所有以sed结尾的行。 . 匹配一个非换行符的任意字符,如:/s.d/匹配s后接一个任意字符,最后是d。