初始化mysql并设置开机自动启动

举报
snowofsummer 发表于 2021/02/07 10:25:25 2021/02/07
【摘要】 1,初始化环境useradd mysql mkdir /3333mkdir /3333/datamkdir /3333/logmkdir /3333/runtouch /3333/log/db.logchown -R mysql:mysql /33332,初始化数据库,无密码[root@db01 data]# /opt/mysql/bin/mysqld --datadir=/3333/dat...

1,初始化环境

useradd mysql 
mkdir /3333
mkdir /3333/data
mkdir /3333/log
mkdir /3333/run
touch /3333/log/db.log
chown -R mysql:mysql /3333

2,初始化数据库,无密码

[root@db01 data]# /opt/mysql/bin/mysqld --datadir=/3333/data  --user=mysql --initialize-insecure
2021-02-07T02:12:02.462057Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-02-07T02:12:02.773084Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-02-07T02:12:02.825583Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-02-07T02:12:02.887143Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: de29a256-68e9-11eb-b2ef-000c29a91aed.
2021-02-07T02:12:02.887685Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-02-07T02:12:02.888181Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

3,初始化数据库

cat >> /3333/data/my.cnf<<EOF
[mysqld]
port=3333
datadir=/3333/data
socket=/3333/mysql.sock
[mysqld_safe]
log-error=/3333/log/db.log
pid-file=/3333/run/db.pid
EOF

4,设置开机自动启动脚本

[root@db01 support-files]# pwd
/opt/mysql/support-files
[root@db01 support-files]# cp mysql.server mysql3333
[root@db01 support-files]# chmod +x mysql3333


support-files 文件设置开机启动脚本:
1,datadir=/3333/data
2,lockdir='/3333'
3,启动参数文件my.cnf,放到datadir目录(extra_args="-e $datadir/my.cnf)

 

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。