本文主要是介绍mac上mysql.tar.gz的安装图解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文主要讲述mac下5.6/5.7/8.0用tar.gz方式安装的mysql数据库,并晒出简单的shell脚本和执行方式,自测可以通过
主要功能点:
mysql-install.sh:安装,配置环境变量,开机自启动,修改默认密码
mysql-config.sh:建库,使用sql文件还原,创建用户和授权
mysql-backup.sh:备份,清楚历史备份
版本:
mac---macOS Mojave 10.14 18A391 Lazy Installer.cdr
mysql 5.6---5.6.33
mysql 5.7---5.7.31
mysql 8.0---8.0.22
使用说明:
1-下载下来的tar.gz文件需要先解压,然后重新命名为mysql.tar.gz
2-5.7和8.0版本需要预先在mysql文件夹下创建data的文件夹
3-解压脚本:
例如5.7版本的tar.gz文件:
解压到tar.gz包的同级目录下:
sudo tar xvf mysql-5.7.31-macos10.14-x86_64.tar.gz
修改文件夹名称:
sudo mv mysql-5.7.31-macos10.14-x86_64 mysql
如果5.7和8.0版本需要在mysql文件夹下创建data目录
切入mysql文件夹下
sudo mkdir data
注意:切到mysql的同级目录下,然后压缩文件夹
sudo tar cvf mysql.tar.gz mysql
4-下载
https://downloads.mysql.com/archives/community/
5.6
5.7
8.0
5-文件列表
mysql-install.sh:安装脚本,需要com.oracle.oss.mysql.mysqld.plist,my.cnf,mysql.tar.gz等文件(mysql.tar.gz为安装文件,my.cnf为配置文件,com.oracle.oss.mysql.mysqld.plist为开机自启动脚本)
执行方式:
sudo ./mysql-install.sh
执行结果:
mysql-config.sh:配置文件,需要sql文件(.sql文件为还原数据库的sql,不包括创建用户和授权)
执行方式:
sudo ./mysql-config.sh
执行结果:
mysql-backup.sh:备份文件,备份结果在该脚本所在目录
执行方式:
sudo ./mysql-backup.sh
执行结果:
脚本放送:
5.6-mysql-install.sh
#!/bin/bash#the parameters
_install_path=/usr/local_mysql_path=/usr/local/mysql_my_path=/etc_root_password=ABCDEFG_cur_path=$(cd $(dirname $0); pwd)_comp_file=$_cur_path/mysql.tar.gz_my_file=$_cur_path/my.cnf_install_log=$_cur_path/install_log.txt_bin_path=$_mysql_path/bin_self_start_dir=/Library/LaunchDaemons_self_start_file=com.oracle.oss.mysql.mysqld.plist
################################decompression the file
tar vxf $_comp_file -C $_install_pathif [ ! $? -eq 0 ]; thenecho 'Unzip failed!'>>$_install_logecho 'Unzip failed!'exit 1
ficd $_mysql_path
chown -R _mysql .
chgrp -R _mysql .#put the my.cnf to
cp $_my_file $_mysql_path/my.cnfif [ ! $? -eq 0 ]; thenecho 'Fail to copy my.cnf!'>>$_install_logecho 'Fail to copy my.cnf!'exit 3
fi##init mysql
./scripts/mysql_install_db --user=_mysql --basedir=$_mysql_path --datadir=$_mysql_path/data
if [ ! $? -eq 0 ]; thenecho 'Install Failed!'>>$_install_logecho 'Install Failed!'exit 5
fi##set path environment
echo export PATH=${PATH}:/usr/local/mysql/bin >> ~/.bash_profile
echo source ~/.bash_profile >> ~/.zshrc
source ~/.bash_profileif [ ! $? -eq 0 ]; thenecho 'Set Environment Path Failed!'>>$_install_logecho 'Set Environment Path Failed!'exit 6
fi##start mysql
$_mysql_path/support-files/mysql.server startif [ ! $? -eq 0 ]; thenecho 'Start mysql server Failed!'>>$_install_logecho 'Start mysql server Failed!'exit 7
ficp $_cur_path/$_self_start_file $_self_start_dir
launchctl load -w $_self_start_dir/$_self_start_fileif [ ! $? -eq 0 ]; thenecho 'Set self-starting Failed!'>>$_install_logecho 'Set self-starting Failed!'exit 8
fi##modify the password of root
./bin/mysqladmin -u root password $_root_passwordif [ ! $? -eq 0 ]; thenecho 'Fail to reset the password of root!'>>$_install_logecho 'Fail to reset the password of root!'exit 9
fimysql -u root -p$_root_password << EOFdrop user ''@'localhost';drop user root@'::1';drop user root@127.0.0.1;GRANT all privileges ON *.* TO roo
这篇关于mac上mysql.tar.gz的安装图解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!