#下载mysql的二进制包:
[[email protected] src]# wget http://down.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
1创建用户和组
[[email protected] src]# groupadd -r mysql
[[email protected] src]# useradd -M -s /sbin/nologin -g mysql mysql
2解压软件至/usr/local:
[email protected] ~]# ls
anaconda-ks.cfg mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[[email protected] ~]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[[email protected] local]# ls
bin games lib libexec mysql-5.7.23-linux-glibc2.12-x86_64 share
etc include lib64 mysql sbin src
3建立一个软连接,并将mysql的路径写入到环境变量中:
[[email protected] ~]# ln -s /usr/local/mysql-5.7.23-linux-glibc2.12-x86_64/ /usr/local/mysql
[[email protected] ~]# ll /usr/local/ | grep mysql
lrwxrwxrwx. 1 root root 47 Sep 26 01:48 mysql -> /usr/local/mysql-5.7.23-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Sep 26 01:43 mysql-5.7.23-linux-glibc2.12-x86_64
[[email protected] ~]# vim /etc//profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[[email protected] ~]# . /etc/profile.d/mysql.sh
4创建mysql存放数据的目录,并修改属组和属主为mysql:
[[email protected] ~]# mkdir /opt/mysql
[[email protected] ~]# chown -R mysql.mysql /opt/mysql/
[[email protected] ~]# ll /opt/mysql/ -d
drwxr-xr-x. 2 mysql mysql 6 Sep 25 13:10 /opt/mysql/
5添加环境变量:
[[email protected] ~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[[email protected] ~]# . /etc/profile.d/mysql.sh
[[email protected] ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
6初始化数据库,并记录下随机密码,最后一排结尾即是第一次登陆的随机密码:
[[email protected] ~]# mysqld --initialize --user=mysql --datadir=/opt/mysql
.......
2018-09-26T05:53:39.169155Z 1 [Note] A temporary password is generated for [email protected]: CyVJ5ZHh;H1f
7修改mysql的配置文件:
[[email protected] ~]# cat > /etc/my.cnf << EOF
> [mysqld]
> datadir = /opt/mysql
> basedir = /usr/local/mysql
> socket = /tmp/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
8修改etc/init.d的配置文件:
[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/mysql 修改启动路径
8:启动服务修改密码:
[email protected] ~]# service mysqld start
Starting MySQL.Logging to ‘/opt/mysql/bogon.err‘.
. SUCCESS!
[[email protected] ~]#mysql -u root -p
Enter password:
mysql> set password=password(‘lzh123!‘);
Query OK, 0 rows affected, 1 warning (0.01 sec)
[[email protected] ~]# vim .my.cnf
[mysql]
user=root
password=lzh123!
[[email protected] ~]# mysql
mysql>
原文地址:http://blog.51cto.com/13945839/2286048
时间: 2024-11-08 23:03:07