Linux服务器---安装mysql

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:
安装mysql
1、检测是否已安装mysql
      [root@localhost bin]#  rpm -qa | grep mysql
      mysql-libs-5.1.71-1.el6.i686
      [root@localhost bin]

2、安装mysql和mysql-server 
      [root@localhost bin]#  yum install -y mysql
      [root@localhost bin]#  yum install -y mysql-server

3、启动mysql,注意这里的服务名字是“mysqld”
      [root@localhost bin]#  service mysqld start
      shell-init: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
      chdir: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
      初始化 MySQL 数据库: Installing MySQL system tables...
      OK
      Filling help tables...
      OK                                                          [确定]
      正在启动 mysqld:                                          [确定]
      [root@localhost bin]# 

4、配置MySQL开机启动 
      [root@localhost bin]#  chkconfig mysqld on
      [root@localhost bin]#  chkconfig --list mysqld
      mysqld          0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
      [root@localhost bin]# 

5、设置root用户密码 ,设置密码的命令是“mysqladmin -u 用户名password 密码”
      [root@localhost bin]#  mysqladmin -u root password 543092   //密码是543092

6、修改密码,命令是“mysqladmin -u 用户名 -p password 新密码” 
      [root@localhost bin]#  mysqladmin -u root -p password 123456     //新密码123456
      Enter password:        //这里要求输入旧密码
      [root@localhost bin]# 

7、mysql配置文件“/etc/my.cnf” 
      [root@localhost bin]#  cat /etc/my.cnf  
      [mysqld]
       datadir=/var/lib/mysql             //数据库文件目录
      socket=/var/lib/mysql/mysql.sock     //socket文件

       user=mysql
      # Disabling symbolic-links is recommended to prevent assorted security risks
      symbolic-links=0


       [mysqld_safe]
      log-error=/var/log/mysqld.log      //日志文件
      pid-file=/var/run/mysqld/mysqld.pid     //进程pid文件



8、修改端口
1)mysql默认的端口是3306,可以使用netstat来查看
      [root@localhost bin]#  netstat -tunlp | grep mysqld
      tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      4339/mysqld         
2)端口在配置文件中修改,打开配置文件,在后面追加一句话”port=xxx” 
      [root@localhost bin]#  gedit /etc/my.cnf
       port=3307       
3)重启myslqd服务,查看端口 
      [root@localhost bin]#  service mysqld restart
      shell-init: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
      chdir: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
      ^[[A停止 mysqld:                                          [确定]
      正在启动 mysqld:                                          [确定]
      [root@localhost bin]#  netstat -tunlp | grep mysqld
      tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      4604/mysqld      
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
21 0
|
3天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
13 0
|
6天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
149 1
|
1天前
|
监控 Linux 网络安全
Linux服务器如何查询连接服务器的IP
【4月更文挑战第15天】Linux服务器如何查询连接服务器的IP
8 1
|
2天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
40 2
|
2天前
|
存储 分布式计算 NoSQL
MongoDB的简介和安装(在服务器上)
MongoDB的简介和安装(在服务器上)
11 0
|
2天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
5 0
|
2天前
|
Ubuntu Linux 开发工具
WSL2(3)安装Linux headers完美解决方案
WSL2(3)安装Linux headers完美解决方案
4 0
|
3天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(7)Ubuntu20.04 arm64安装Docker
Linux(7)Ubuntu20.04 arm64安装Docker
15 0
|
6天前
|
网络协议 安全 Linux
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器