重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本文主要给大家介绍MySQL-5.7.18自定义安装路径讲义,其所涉及的东西,从理论知识来获悉,有很多书籍、文献可供大家参考,从现实意义角度出发,创新互联累计多年的实践经验可分享给大家。
创新互联成立十余年来,这条路我们正越走越好,积累了技术与客户资源,形成了良好的口碑。为客户提供网站建设、成都网站设计、网站策划、网页设计、域名注册、网络营销、VI设计、网站改版、漏洞修补等服务。网站是否美观、功能强大、用户体验好、性价比高、打开快等等,这些对于网站建设都非常重要,创新互联通过对建站技术性的掌握、对创意设计的研究为客户提供一站式互联网解决方案,携手广大客户,共同发展进步。
libaio
yum install -y libaio
useradd -s /bin/false -M mysql
cd /tools
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
tar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /application/
cd /application/
mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql-5.7.18
ln -s mysql-5.7.18/ mysql
mkdir mysql/mysql-files
chmod 750 mysql/mysql-files
chown -R mysql:mysql mysql-5.7.18/
cd mysql
会在mysql目录内生成一个data目录,存放数据库的目录
bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
返回结果最后一行的末尾有随机密码,我的记下来:wa0I:1w?V--a
2017-04-28T02:49:00.853710Z 1 [Note] A temporary password is generated for root@localhost: wa0I:1w?V--a
想设置默认密码为空则将--initialize选项替换为--initialize-insecure选项
bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
bin/mysql_ssl_rsa_setup --datadir /application/mysql/data/
指定data目录的路径
chown -R root .
chown -R mysql data mysql-files
除了mysql目录下的data目录和mysql-files目录所属用户不变,其他所有文件的所属用户改为root
sed -i 's/^datadir=\/var\/lib\/mysql/datadir=\/application\/mysql\/data/g' /etc/my.cnf
sed -i 's/^socket=\/var\/lib\/mysql\/mysql.sock/socket=\/tmp\/mysql.sock/g' /etc/my.cnf
sed -i 's/^log-error=\/var\/log\/mariadb\/mariadb.log/log-error=\/application\/mysql\/data\/err.log/g' /etc/my.cnf
sed -i 's/^pid-file=\/var\/run\/mariadb\/mariadb.pid/pid-file=\/application\/mysql\/data\/mysql.pid/g' /etc/my.cnf
等价于:
vi /etc/my.cnf
datadir=/application/mysql/data
socket=/tmp/mysql.sock
log-error=/application/mysql/data/err.log
pid-file=/application/mysql/data/mysql.pid
/etc/my.cnf Content:
[mysqld]
datadir=/application/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/application/mysql/data/err.log
pid-file=/application/mysql/data/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
cp support-files/mysql.server /etc/init.d/mysql
将mysql的启动程序拷贝到/etc/init.d/目录下,以便启动程序
方法一:
思路是给配置文件提供的变量进行赋值。较麻烦。
sed -i 's/^basedir=/basedir=\/application\/mysql/g' /etc/init.d/mysql
sed -i 's/^datadir=/datadir=\/application\/mysql\/data/g' /etc/init.d/mysql
sed -i 's/^mysqld_pid_file_path=/mysqld_pid_file_path=\/application\/mysql\/data\/mysql.pid/g' /etc/init.d/mysql
等价于将45、46两行
basedir=
datadir=
mysqld_pid_file_path=
替换成
basedir=/application/mysql
datadir=/application/mysql/data
mysqld_pid_file_path=/application/mysql/data/mysql.pid
方法二(推荐):
思路是将脚本的默认地址(/usr/local/mysql)直接替换成自定义路径(/application/mysql),便不用给变量赋值
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysql
到这里mysql安装完成可以正常启动
将mysql命令创建软链接到环境变量的目录,使用户可以在变量找到相应的命令
ln -s /application/mysql/bin/* /usr/local/sbin
[root@www mysql]# mysql -u root -p
Enter password: #输入之前保存的随机密码drRR0 ... mysql> #成功登陆到mysql控制台 mysql> alter user 'root'@'localhost' identified by 'NewPassWord'; #将密码修改为NewPassWord Query OK, 0 rows affected (0.01 sec) #修改成功 mysql> quit Bye [root@www mysql]# or mysql> ^DBye [root@www mysql]# mysql -u root -p service mysql start service mysql stop service mysql restart 看了以上mysql-5.7.18自定义安装路径讲义介绍,希望能给大家在实际运用中带来一定的帮助。本文由于篇幅有限,难免会有不足和需要补充的地方,大家可以继续关注创新互联行业资讯板块,会定期给大家更新行业新闻和知识,如有需要更加专业的解答,可在官网联系我们的24小时售前售后,随时帮您解答问题的。 修改密码sql语句
键入quit或Ctrl + d退出
4.常用命令
进入mysql
启动mysql
停止mysql
重启mysql
文章名称:mysql-5.7.18自定义安装路径讲义
分享地址:http://cqcxhl.cn/article/iepjdo.html