To initialize the data directory, invoke mysqld with the --initialize or --initialize-insecure option, depending on whether you want the server to generate a random initial password for the 'root'@'localhost' account, or to create that account with no password:
Use --initialize for “secure by default” installation (that is, including generation of a random initial root password). In this case, the password is marked as expired and you must choose a new one.
With --initialize-insecure , no root password is generated. This is insecure; it is assumed that you intend to assign a password to the account in a timely fashion before putting the server into production use.
可以使用 grep "password" /path to you mysql-err.log 找到使用--initialize生成的随机密码
三、 管理 MySQL
3.1 传统方式管理
配置管理文件 cp -a /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
修改如下两行 (大约46/47两行) vim /etc/rc.d/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql
管理 mysql /etc/rc.d/init.d/mysql start / status / stop / reload / restart
3.2 使用 systemd 管理
完成传统方式管理的配置之后添加文件如下 vim /usr/lib/systemd/system/mysqld.service
[Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/local/docker/dockerd # ExecStart=/usr/local/docker/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ## 注意这种配置的写法,区别在后面会介绍 ExecReload=/bin/kill -s HUP $MAINPID TimeoutStartSec=0 RestartSec=2 Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make # this option work for either version of systemd. StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNPROC=infinity LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it. # Only systemd 226 and above support this option. TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes
# kill only the docker process, not all processes in the cgroup KillMode=process OOMScoreAdjust=-500
[Install] WantedBy=multi-user.target
docker.socket
# vim /usr/local/docker/docker.socket [Unit] Description=Docker Socket for the API
[Socket] # If /var/run is not implemented as a symlink to /run, you may need to # specify ListenStream=/var/run/docker.sock instead. ListenStream=/var/run/docker.sock SocketMode=0660 SocketUser=root SocketGroup=docker
[Socket] # If /var/run is not implemented as a symlink to /run, you may need to # specify ListenStream=/var/run/docker.sock instead. ListenStream=/var/run/docker.sock SocketMode=0660 SocketUser=root SocketGroup=docker