CentOS7默认数据库是mariadb, 但是 好多用的都是mysql ,但是CentOS7的yum源中默认好像是没有mysql的。
如果第一次使用Linux的童鞋可以类比下Windows的安装,步骤都一样,下载-》解压缩-》安装(可指定路径),只不过Linux是用命令安装,不是鼠标操作,而且Linux是文件系统,一切皆文件,也就是说Linux没有和Windows一样有CDE等盘符的,Linux都是以文件作为路径。最后说一句,要多动手操作
准备:
VMware
centos7虚拟主机
mysql资源路径:
http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
- 卸载 先停掉mysql进程 没有安装过的可以直接跳过
pkill -9 mysqld
rpm -qa|grep -i mysql
用命令 yum -y remove
yum -y remove mysql-community-client-5.6.38-2.el7.x86_64
卸载不掉的用 rpm -ev
依次卸载 直到没有
2.下载mysql的repo源 /**纠正一下,这源下载的是最新的版本 ****/
可以指定安装目录 yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server )我没试,这样装环境变量配置都不用你管,装上直接启动就行。安装路径是默认的。
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
下载完后就是一个mysql57-community-release-el7-7.noarch.rpm的文件,可以用以下命令查看该文件都包含哪些包:
rpm -qpl mysql57-community-release-el7-7.noarch.rpm
安装rpm包
rpm -ivh mysql57-community-release-el7-7.noarch.rpm
安装完上述包后,查看yum库,
yum list mysql*
之后就可以用yum安装MySQL了:
yum install mysql-community-server
安装完成。
查看已安装版本
mysql -V
设置mysql密码
1、停止mysql服务
systemctl stop mysqld.service
2、mysql配置文件修改为免密码登录。
vi /etc/my.cfg
修改
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-grant-tables #添加这句话,这时候登入mysql就不需要密码
symbolic-links=0
3、启动 mysql 服务
systemctl start mysqld.service
修改密码
set password for root@localhost=password('123456'); or update user set authentication_string=PASSWORD("123456") where user="root";
4、以root身份登录mysql, 输入密码的时候直接回车
mysql -u root -p #输入命令回车进入,出现输入密码提示直接回车。
mysql> set password for root@localhost = password('123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@localhost = password('123456'); or update user set authentication_string=PASSWORD("123456") where user="root";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>flush privileges; #更新权限
mysql>quit; #退出
数据库安装完成了