Windows下MySQL的安装
- 对下载的工具包进行解压
- 进入到安装目录,新建my.ini文件
[mysqld] # 设置3306端口 port=3306 # 设置mysql的安装目录 ----------是你的文件路径------------- basedir=F:\mysql\mysql5.7.35 # 设置mysql数据库的数据的存放目录 ---------是你的文件路径data文件夹自行创建 datadir=F:\mysql\mysql5.7.35\data # 允许最大连接数 max_connections=20 # 允许连接失败的次数。 max_connect_errors=10 # 服务端使用的字符集默认为utf8mb4 character-set-server=utf8mb4 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # 默认使用“mysql_native_password”插件认证 #mysql_native_password default_authentication_plugin=mysql_native_password [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8mb4 [client] # 设置mysql客户端连接服务端时默认使用的端口 port=3306 default-character-set=utf8mb4
- 以管理员身份运行命令提示符cmd,进入到安装目录的bin目录下
mysqld --install # 显示successfully即为成功
- 输出MySQL的密码
mysqld --initialize --console F:\mysql\mysql5.7.35\bin>mysqld --initialize --console 2022-10-15T02:48:46.260597Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-10-15T02:48:46.771286Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-10-15T02:48:46.806884Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-10-15T02:48:46.888696Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e3e5d408-4c33-11ed-a627-80e82c7421a3. 2022-10-15T02:48:46.892960Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-10-15T02:48:48.918962Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-10-15T02:48:48.919348Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-10-15T02:48:48.922440Z 0 [Warning] CA certificate ca.pem is self signed. 2022-10-15T02:48:49.269783Z 1 [Note] A temporary password is generated for root@localhost: y%6XXmtSF5pd # y%6XXmtSF5pd 就是密码
- 启动mysql
net start mysql
- 登录mysql
mysql -u root -p # 密码是刚才输出的 y%6XXmtSF5pd
- 更改mysql的密码
# ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码'; ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
- 退出
exit
- 配置环境变量
# windows左下角搜索'编辑系统环境变量' # 高级 -- 环境变量 -- 新建 # 变量名:MYSQL_HOME # 变量值:安装路径 # 确定 # 找到Path # 编辑 -- 新建 -- %MYSQL_HOME%\bin # 确定保存
Linux下MySQL的安装
- 创建存放文件的目录
mkdir -p /root/opt/software
- 上传mysql文件 MySQL-5.5.40-1.el7.x86_64.rpm-bundle.tar到software
mv MySQL-5.5.40-1.el7.x86_64.rpm-bundle.tar /指定目录
- 检查是否有自带的数据库
rpm -qa | grep mariadb # 如果有的话进行删除/卸载 rpm -e 文件 --nodeps rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps
- 安装依赖
yum install -y perl
- 在software下创建mysql文件夹
mkdir mysql
- 解压MySQL-5.5.40-1.el7.x86_64.rpm-bundle.tar到mysql文件夹下
tar -xvf MySQL-5.5.40-1.el7.x86_64.rpm-bundle.tar -C /root/opt/software/mysql/
- 安装服务器和客户端
cd mysql # 服务器 rpm -ivh MySQL-server-5.5.40-1.el7.x86_64.rpm # 客户端 rpm -ivh MySQL-client-5.5.40-1.el7.x86_64.rpm
- 启动mysql服务
systemctl start mysql
- 检查mysql服务
systemctl status mysql
- 开启客户端
mysql -uroot
- 设置mysql的密码
mysql> set password=password('123456')
- 设置远程连接
mysql> grant all on *.* to 'root'@'%' identified by '123456';
- 刷新权限
mysql> flush privileges;
- 退出
mysql> exit