Linux -- MySQL的安装(RPM文件安装)

1.rpm包的下载:https://www.mysql.com/downloads/

  • 选择mysql community server里边的在这里插入图片描述在这里插入图片描述
  • 选择操作系统和版本
    在这里插入图片描述

2.安装

  • 清理环境,centos7会自带一个mariadb,查看是否已安装
rpm -qa |grep -i mysql
rpm -qa |grep -i mariadb(centos7默认系统自带的)
  • mariadb是从mysql来的,是它的一个分支,需要清理掉,清理掉mariadb包,rpm -e 加上包名,把mariadb包清掉
    在这里插入图片描述
  • 可以看到用rpm删除会失败,提示有依赖关系的软件需要安装,rpm删除时如果有依赖关系,可以用yum remove + 包名来删除mariadb
    在这里插入图片描述
  • 开始安装
1.上传压缩包
2.解压
3.查看已安装的mysql  rpm -qa |grep mysql
4.删除已安装的mysql  rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
5.安装我们自己的rpm包 rpm -ivh *.rpm
6.设置mysql的root密码,首先后台启动mysql  cd /usr/lib
    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
7.进入mysql终端:mysql -u root mysql
8.设置密码: UPDATE user SET Password=PASSWORD('admin') where USER='root' and host='root' or host='localhost';
9.刷新权限:FLUSH PRIVILEGES;
10.退出mysql  exit;
11.重启mysql:/etc/init.d/mysql restart
12  重新使用新密码登陆 mysql -uroot -p
13. 重新设置一下密码:SET PASSWORD = PASSWORD('admin');
13.开启远程登陆:Grant all privileges on *.* to 'root'@'%' identified by 'admin' with grant option;
14.刷新权限列表 :FLUSH PRIVILEGES;

其他方式

  1. download rpm包
    先确定系统版本
[root@xcldtc5m /]# cat /proc/version
Linux version 2.6.32-431.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 22 03:15:09 UTC 2013
下载mysql rpm包
wget https://mysql.mirrors.pair.com/Downloads/MySQL-5.6/MySQL-server-5.6.22-1.el6.x86_64.rpm
wget https://mysql.mirrors.pair.com/Downloads/MySQL-5.6/MySQL-devel-5.6.22-1.el6.x86_64.rpm
wget https://mysql.mirrors.pair.com/Downloads/MySQL-5.6/MySQL-client-5.6.22-1.el6.x86_64.rpm
  1. 安装
[root@xcldtc5m mysql]# rpm -ivh MySQL-server-5.6.22-1.el6.x86_64.rpm
[root@xcldtc5m mysql]# rpm -ivh MySQL-devel-5.6.22-1.el6.x86_64.rpm
[root@xcldtc5m mysql]# rpm -ivh MySQL-client-5.6.22-1.el6.x86_64.rpm
发现缺libaio.so包
error: Failed dependencies:
/usr/bin/perl is needed by MySQL-server-5.6.22-1.el6.x86_64
libaio.so.1()(64bit) is needed by MySQL-server-5.6.22-1.el6.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.22-1.el6.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.22-1.el6.x86_64
error: Failed dependencies:
/usr/bin/perl is needed by MySQL-server-5.6.22-1.el6.x86_64
解决方法
[root@xcldtc5m mysql]# yum install libaio
[root@xcldtc5m mysql]# yum install perl
若处理mysql版本冲突,先移除已经安装的mysql
[root@xcldtc5m mysql]# yum -y remove mysql-libs-5.1.71*
  1. 修改配置文件位置
root@xcldtc5m mysql]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
  1. 初使化MYSQL及配置密码
[root@xcldtc5m mysql]# /usr/bin/mysql_install_db
[root@xcldtc5m mysql]# service mysql start
[root@xcldtc5m mysql]# cat /ro ot/.mysql_secret
# The random password set for the root user at Sat Feb 7 10:54:24 2015 (local time): VoKvw3vpo_3LiA3c
[root@xcldtc5m mysql]# mysql -uroot -pVoKvw3vpo_3LiA3c
mysql> SET PASSWORD = PASSWORD('2345678');
mysql> exit
[root@xcldtc5m mysql]# mysql -uroot -p2345678
  1. 远程登录配置
mysql> use mysql
mysql> select host ,user ,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *BC1C4715C23459AB982AD2D6617B4F8790161763 |
| xcldtc5m | root | *44CF61DA6CDeeee2085F4598F728CF221DA8F167 |
| 127.0.0.1 | root | *44CF61DA6CD83e32085F4598F728CF221DA8F167 |
| ::1 | root | *44CF61DA6CD86832345F4598F728CF221DA8F167 |
+-----------+------+-------------------------------------------+
mysql> update user set password=password('234567') where user='root';
mysql> update user set host='%' where host='localhost';
  1. 设置开机自启动
[root@xcldtc5m mysql]# chkconfig mysql on
[root@xcldtc5m mysql]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  1. 查看mysql配置文件位
[root@xcldtc5m mysql]# mysqld --verbose --help | grep -A 1 'Default options'
  1. MYSQL默认安装位置
/var/lib/mysql/ #数据库目录 /usr/share/mysql #配置文件目录
/usr/bin #相关命令目录 /etc/init.d/mysql #启动脚本

Linux下MySQL的乱码处理

cd /usr/share/doc/MySQL-server-5.6.25
有一个my-default.cnf文件,将这个文件copy到 /etc/下 并且重命名my.cnf
修改/etc/my.cnf文件,添加如下内容,如果没有client节点,手动添加client节点。
在[client]下添加
default-character-set=utf8
在[mysqld]下添加
character-set-server=utf8
在这里插入图片描述

登录mysql查看编码情况:
show variables like ‘%Character%’;
在这里插入图片描述

发布了66 篇原创文章 · 获赞 18 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Aeve_imp/article/details/99313980