Linux或Windows系统下安装MySQL教程
  一些代码   0 评论   68 浏览量

Linux或Windows系统下安装MySQL教程

  一些代码   0 评论   68 浏览量

Linux下安装MySQL的教程

Linux系统中为了防止手残将docker中的数据库删掉了,因此我们使用服务器中自己的mysql,这样就可以进一步备份数据了。参考安装脚本如下。

# 下载mysql
yum install mysql
# 安装mysql服务
yum install mysql-server
yum install mysql-devel
# 修改字符集
default-character-set=utf-8
#安装服务 
mysqld --install
# 初始化
mysqld --initialize-insecure
#开启数据库服务
net start mysql
#进入数据库
mysql -hlocalhost -uroot -p
#设置密码
set password for root@localhost = password('123456');
shell

修改默认端口,有时候我们在docker中安装了数据库,这时候可能提示3306端口被占用,因此我们将端口进行修改

vi /etc/my.cnf
# 添加新的端口
port=3307
bash

mysql为安全起见,拒绝用户使用root用户,因此需要指定用户

vim /etc/my.cnf
# 添加指定用户
user=mysql
# 重新启动mysql
mysqld restart --user=mysql
# 检查mysqld服务是否运行成功
service mysqld status
bash

检查对应的端口有没有运行lsof -i:3307

Linux重装mysql,失败

# 找到mysql相关文件
find / -name mysql
bash

参考B3log,失败

yum -y install mysql57-community-release-el7-10.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm
ps -ef|grep mysql
find / -name mysql
ln -sf /usr/local/bin/mysql /usr/bin
docker exec -it zipmysql02 /bin/bash
cd /etc/mysql
docker cp zipmysql02:/etc/mysql/conf.d/mysql.cnf /dockerData/mysql
docker cp /dockerData/mysql zipmysql02:/etc/mysql/conf.d/mysql.cnf
cat mysql.cnf
exit
docker restart zipmysql02
bash

继续参考b3log 成功

image.png

启动数据库systemctl start mysqld。配置文件

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
port=3307  
bash

查看初始密码:grep "password" /var/log/mysqld.log

进入数据库:mysql -uroot -p

修改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

开启远程登录:grant all on *.* to root@'%' identified by '123456';

关闭设置密码的规则

#password rules enable/disable
validate_password = off
#0(LOW) 1(MEDIUM) 2(STRONG)
validate_password_policy=0
bash

image.png

windows下安装MySQL的教程

windows11中安装mysql,阿里云数据库下载的镜像地址。我选择是windows的5.8的版本。使用管理员身份打开cmd,找到安装的目录执行mysqld --install注册服务,然后启动mysql服务。使用navicat工具测试连接,或者使用免费的SQL客户端测试dbeaver是否连接成功。找到安装目录net start mysql。将目录加上引号。

windows下设置新的密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
bash

常用的DML/DQL语言

# 更新操作
UPDATE table SET column1 = value1, column2 = value2, ... WHERE condition;
# 添加操作
INSERT INTO table (column1, column2, ...) VALUES (value1, value2, ...);
sql
本文由 木之下 发表, 最后编辑时间为:2023-11-28 20:01:53
(完)