1. windows安装
1.1 下载
下载地址:MySQL :: Download MySQL Community Server
直接点no thanks,just start my download,直接下载
1.2 解压
1.3 进入到bin目录下
初始化数据库,然后记录下方框里的内容,这是随机生成的密码(uq,hau82eNel),下面登录数据库需要用到初始化数据库命令: mysqld --initialize --console
账号:root,密码:BgHNLik4eM_a
1.4 将mysql安装为windows的服务
mysqld -install
会发现安装失败:原因是cmd未使用管理员身份打开,重新用管理员身份打开cmd就可以了
1.5 启动mysql服务
输入net start mysql或sc start mysql
1.6 登录
登录数据库,使用之前记录的密码:mysql -u root -p
之前刚开始给的初始密码:BgHNLik4eM_a
1.7 修改密码
alter user 'root'@'localhost' identified by '想要设置的密码';
commit;
1.8 退出数据库
quit;
转载:windows安装mysql详细步骤_小了白了白¥的博客-CSDN博客_mysql windows 安装
2. Linux安装
2.1 下载
下载地址
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2.2 用yum安装
yum -y install /opt/software/mysql57-community-release-el7-10.noarch.rpm
2.3 安装mysql server
重新导入秘钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install -y mysql-server
安装完毕之后启动mysql:
systemctl start mysqld.service
查看进程
ps -ef | grep mysqld
2.4 设置mysql的相关配置
设置开启自启动
systemctl enable mysqld.service
修改密码
grep "password" /var/log/mysqld.log
进入数据库
mysql -uroot -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
注意:其中‘new password’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/';:等),不然不能配置成功
2.5 设置远程连接
其实到这一步只有服务器本地才能连接,所以我要开启外面可以连接的功能:
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
刷新权限:
flush privileges;
退出:exit
2.6 更改mysql的语言
我们先退出,然后去修改 /etc/my.cnf
因为在centos中所有的配置文件几乎都在 etc 目录下
vim /etc/my.cnf
[client]
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
重启mysql
service mysqld restart
这个时候再进去开就是utf-8了!!