在Linux与Windows环境下安装MySQL
Windows环境下的安装
下载MySQL
下载MySQL,解压得到MySQL实例,MySQL实例版本:5.7.33
创建data目录与my.ini文件
配置my.ini
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=D:\Mysql\mysql-master
# 设置mysql数据库的数据的存放目录
datadir=D:\Mysql\mysql-master\data
初始化MySQL数据文件
生成临时密码:+VoXweWtn0nk
D:\Mysql\mysql-master\bin>mysqld --initialize --user=mysql --console
2021-02-06T14:13:47.509372Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-02-06T14:13:47.782394Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-02-06T14:13:47.830502Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-02-06T14:13:47.923373Z 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: 878fec60-6885-11eb-81a5-002324ce8b45.
2021-02-06T14:13:47.927616Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-02-06T14:13:49.170165Z 0 [Warning] CA certificate ca.pem is self signed.
2021-02-06T14:13:50.110769Z 1 [Note] A temporary password is generated for root@localhost: +VoXweWtn0nk
安装MySQL服务
无安装权限
D:\Mysql\mysql-master\bin>mysqld --install
Install/Remove of the Service Denied!
D:\Mysql\mysql-master\bin>
使用管理员操作
D:\Mysql\mysql-backup\bin>mysqld --install
Service successfully installed.
D:\Mysql\mysql-backup\bin>
启动MySQL
D:\Mysql\mysql-master\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
登录MySQL
使用初始化MySQL数据文件生成的临时密码+VoXweWtn0nk
D:\Mysql\mysql-master\bin>mysql -u root -P 3306 -h 127.0.0.1 -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
重置登录密码
任何操作将会出现:You must reset your password using ALTER USER statement before executing this statement 提示,要求必须修改密码
MySQL5.7.6以前版本:
mysql> SET PASSWORD = PASSWORD('123456');
MySQL5.7.6以后版本:
mysql> ALTER USER USER() IDENTIFIED BY '123456';
mysql> alter user user() identified by "123456";
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
Linux环境下的安装
环境检查
1.检查是否有自带的mysql
rpm -qa | grep mysql
2.卸载自带的mysql
普通删除模式
rpm -e mysql
强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
rpm -e --nodeps mysql
查找及删除对应文件夹
whereis mysql
find / -name mysql
下载MySQL
1.官网下载适合的版本,下载后上传到Linux。
2.Linux中下载:
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
解压MySQL安装包
tar zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
将解压得到的文件移动到合适的安装位置
mv mysql-5.7.32-linux-glibc2.12-x86_64 /usr/local/
重命名
mv mysql-5.7.32-linux-glibc2.12-x86_64 mysql
创建数据库保存位置
mkdir /usr/local/mysql/data
新建MySQL用户、组及目录
groupadd mysql
useradd -r -g mysql mysql
赋予读写权限
chown -R mysql /usr/local/mysql/
chgrp -R mysql /usr/local/mysql/
初始化安装MySQL
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
日志末尾: A temporary password is generated for root@localhost: _tjqD4Ip,GuR。root@localhost:后面字符串则为MySQL管理员临时登录密码。
编辑配置文件my.cnf
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
character_set_server=utf8
max_connections=5000
default-time_zone = '+8:00'
启动MySQL服务器
cd /usr/local/mysql/support-files
./mysql.server start
登录MySQL
mysql -uroot -p
若出现 -bash: mysql: command not found
添加软连接,并重新启动MySQL
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
修改密码
set password=password('新密码');
退出MySQL
1.quit
2.exit
远程授权
设置root账户的host地址,修改后才可以远程连接。
grant all privileges on *.* to 'root'@'%' identified by '新密码';
flush privileges;
开机自启
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
MySQL相关命令
service mysqld start
service mysqld stop
service mysqld restart
#重载配置
service mysqld reload
#端口信息
netstat -anpt | grep mysql
#状态信息
service mysql status
#进程信息
ps -elf | grep mysqld
#结束进行
kill -9 进程号
Docker安装MySQL
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/137060.html