您现在的位置是:网站首页> 编程开发> 数据库 编程开发
Linux服务器下安装Mysql服务
2021-04-23【数据库】 1801人已围观
简介1.下载Mysql5.3安装包l链接:https://pan.baidu.com/s/1zsRw1VBRDO9dbb97SMEopQ密码:lo932.把mysql_install_v3.1.sh和pe
Linux服务器下安装Mysql服务
最后更新:2021-04-23 15:10:32
推荐指数:
1.下载Mysql5.3安装包
l链接:https://pan.baidu.com/s/1zsRw1VBRDO9dbb97SMEopQ
密码:lo93
2.把mysql_install_v3.1.sh和percona-server-5.7.11.tgz上传到服务器的/data目录
3.解压
tar -zxvf percona-server-5.7.11.tgz
4.安装libaio
yum install libaio -y
5.修改mysql_install_v3.1.sh配置
修改20行:mysql_port=端口号
修改21行:mysql_server_id=IP尾号+端口号
修改22行:物理内存1/2
6.运行sh脚本(执行结束后就安装完成了)
sh mysql_install_v3.1.sh
7.编辑存储目录
vim /etc/init.d/mysqld
basedir=/usr/local/mysql5.7.11
datadir=/data/mysql/mysql30306/mydata
8.映射运行目录
ln -s /opt/mysql5.7.11/percona-server-5.7.11/bin/mysql /usr/bin/mysql
ln -s /opt/mysql5.7.11/percona-server-5.7.11/bin/mysqld /usr/bin/mysqld
9.运行
mysqld --defaults-file=/etc/my30306.cnf --user=mysql &
10.找到mysql的初始化密码
####因为mysql在安装的时候第一次密码是生成的,需要执行下边这句去查一下默认密码是什么
cat /data/mysql/mysql30306/logs/mysql-30306.err |grep 'A temporary password is generated for'
以上命令可以查询初始化密码
11.登录客户端
mysql -u root --password=${password} -S /data/mysql/mysql${mysql_port}/mysql.sock -hlocalhost
${password} :第10步的初始密码
${mysql_port}:自己定义的端口
12.修改root密码
step 1: SET PASSWORD = PASSWORD('dou123456');
step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
step 3: flush privileges;
source /etc/profile
这样就安装完成了。
################################################创建mysql用户#创建一个全部权限新用户
grant all privileges on *.* to 'douhaichao'@'%' IDENTIFIED BY 'dou123456';
#创建只读用户
GRANT Select ON *.* TO 'spyj_read'@'%' IDENTIFIED BY '4ip60Ctam2XjJ59e';
#刷新
flush privileges;
################################################
###从主库上备份
mysqldump -uroot -p --set-gtid-purged=off -S /data/mysql/mysql30306/mysql.sock marvel > marvel.sql
###在从库上开始还原
进入mysql客户端:create database marvel;
退出mysql客户端:mysql -u root --password=iLtbrVJaFfTtBIdB -S /data/mysql/mysql30306/mysql.sock -hlocalhost marvel < /tmp/marvel.sql
###############################################自动备份
自动备份:
vi /usr/sbin/bakmysql.sh
####################################
db_user="spyjdba"
db_passwd="xY59S7uf2ZpgV6Xt"
db_name="spyjdb"
# the directory for story your backup file.you shall change this dir
backup_dir="/usr/software/backup/mysqlbackup"
# date format for backup file (dd-mm-yyyy)
time="$(date +"%Y%m%d%H%M%S")"
/opt/mysql5.7.11/percona-server-5.7.11/bin/mysqldump -u$db_user -p$db_passwd $db_name -S /data/mysql/mysql30306/mysql.sock > "$backup_dir/$db_name"_"$time.sql"
###################################
chmod 777 /usr/sbin/bakmysql.sh
crontab -e
00 23 * * * /usr/sbin/bakmysql.sh
使用 service crond restart 或者/etc/init.d/crond restart(Centos7下为systemctl restart crond)
==引用
//启动服务
service crond start
//关闭服务
service crond stop
//重启服务
service crond restart
//重新载入配置
service crond reload
//查看服务状态
service crond status
==
很赞哦! (0)
下一篇:Linux服务器下安装Redis
文章评论
验证码: