安装mysql

查询yum服务器上可用的关于mysql的安装包:

[root@localhost ~]# yum list | grep mysql
mysql-libs.x86_64 5.1.71-1.el6 @anaconda-CentOS-201311272149.x86_64/6.5
apr-util-mysql.x86_64 1.3.9-3.el6_0.1 base
bacula-director-mysql.x86_64 5.0.0-13.el6 base
bacula-storage-mysql.x86_64 5.0.0-13.el6 base
dovecot-mysql.x86_64 1:2.0.9-22.el6 base
freeradius-mysql.x86_64 2.2.6-6.el6_7 base
libdbi-dbd-mysql.x86_64 0.8.3-5.1.el6 base
mod_auth_mysql.x86_64 1:3.0.0-11.el6_0.1 base
mysql.x86_64 5.1.73-8.el6_8 base
mysql-bench.x86_64 5.1.73-8.el6_8 base
mysql-connector-java.noarch 1:5.1.17-6.el6 base
mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 base
mysql-devel.i686 5.1.73-8.el6_8 base
mysql-devel.x86_64 5.1.73-8.el6_8 base
mysql-embedded.i686 5.1.73-8.el6_8 base
mysql-embedded.x86_64 5.1.73-8.el6_8 base
mysql-embedded-devel.i686 5.1.73-8.el6_8 base
mysql-embedded-devel.x86_64 5.1.73-8.el6_8 base
mysql-libs.i686 5.1.73-8.el6_8 base
mysql-libs.x86_64 5.1.73-8.el6_8 base
mysql-server.x86_64 5.1.73-8.el6_8 base
mysql-test.x86_64 5.1.73-8.el6_8 base
pcp-pmda-mysql.x86_64 3.10.9-9.el6 base
php-mysql.x86_64 5.3.3-49.el6 base
qt-mysql.i686 1:4.6.2-28.el6_5 base
qt-mysql.x86_64 1:4.6.2-28.el6_5 base
rsyslog-mysql.x86_64 5.8.10-10.el6_6 base
rsyslog7-mysql.x86_64 7.4.10-7.el6 base

安装:

[root@localhost ~]# yum install -y mysql-server mysql mysql-devel

查询是否安装好:

[root@localhost ~]# rpm -qa | grep mysql

启动服务:

[root@localhost ~]# service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run:
/usr/bin/mysql_secure_installation which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ]
Starting mysqld: [ OK ]

登录

设置root用户的密码:

[root@localhost ~]# /usr/bin/mysqladmin -u root password '123456'

根据设置的密码登录:

[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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>

创建新的用户nick-huang,允许远程登录,并授予权限:

grant all privileges on *.* to nick-huang @"%" identified by '123456';
flush privileges;

如果登录权限有问题,可以用安全模式登录并设置好权限:

[root@localhost ~]# service mysqld stop
Stopping mysqld: [ OK ]
[root@localhost ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 3766
[root@localhost ~]# 170409 06:37:18 mysqld_safe Logging to '/var/log/mysqld.log'.
170409 06:37:18 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql [root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mysql -u root

然后就可以通过SQL修改mysql.user表的字段。

比如:

  • 修改密码:mysql> update mysql.user set password = password('123456') where user = 'root';
  • 修改登录主机:修改host字段为%,则可在任意IP的主机连接MySQL

设置完后重启mysqld服务:

[root@localhost ~]# service mysqld stop

修改监听端口

备份配置文件,然后修改:

cp /etc/my.cnf /etc/my.cnf.bak.20170808
vi /etc/my.cnf

[mysqld]下添加:port=30000

然后重启:service mysqld restart

状态的查询

SHOW SESSION STATUS;SHOW STATUS;,查询当前会话的状态

SHOW GLOBAL STATUS;,查询全局的状态

具体的解析可参考MySQL运行状态show status中文详解

当然,状态太多,可以通过like查找,比如查询最大已用连接数:SHOW GLOBAL STATUS LIKE 'Max_used_connections';

其它

参数设置

查询

SHOW SESSION VARIABLES;SHOW VARIABLES;,查询当前会话的参数

SHOW GLOBAL VARIABLES;,查询全局的参数

也可以模糊查询,比如查询允许最大连接数:SHOW GLOBAL VARIABLES LIKE '%max_connections%';

设置参数

例子,设置连接空闲超时时间为2200秒:set global wait_timeout = 2200;,关于wait_timeout参数,有经典的8小时问题,详情请参考:mysql经典的8小时问题-wait_timeout

连接进程

查询

通过SHOW PROCESSLIST;SHOW FULL PROCESSLIST;查看连接进程列表。实际的数据可以通过查询具体表得到:

select * from information_schema.`PROCESSLIST` t;

比如,查询各主机的连接进程数量:

SELECT SUBSTRING_INDEX(t.`HOST`, ':', 1), COUNT(*), GROUP_CONCAT(t.`COMMAND`) FROM information_schema.`PROCESSLIST` t GROUP BY SUBSTRING_INDEX(t.`HOST`, ':', 1) ORDER BY SUBSTRING_INDEX(t.`HOST`, ':', 1);

比如,查询某主机连接各库的进程数量:

SELECT t.`DB`, COUNT(*) FROM information_schema.`PROCESSLIST` t WHERE t.`HOST` LIKE '10.0.76.34%' GROUP BY t.`DB`;

删除连接进程

可以通过语句删除指定的连接进程:kill connection 进程ID(SHOW PROCESSLIST的ID列);

【MySQL】MySQL在CentOS的搭建的更多相关文章

  1. centos 7 lamp (linux+apache+mysql+php)开发环境搭建(转+原创)

    准备篇:CentOS 7.0系统安装配置图解教程 http://www.jb51.net/os/188487.html 一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是fi ...

  2. centos 下搭建 php环境(2) mysql 安装

    CentOS下的MySQL 5.1安装   01 1.下载源码包 wget http://mysql.llarian.net/Downloads/MySQL-5.1/mysql-5.1.63.tar. ...

  3. centos 7 搭建 LNMP ( Linux+Nginx+MySQL+PHP )

    操作系统 | CentOS Linux release 7.6.1810 (Core) [root@localhost ~# cat /etc/redhat-release CentOS Linux ...

  4. 阿里云上安装mysql步骤/ 阿里云ECS搭建Java+mysql+tomcat环境

    使用阿里云ECS挺长一段时间了.这两天碰巧朋友小白让我一步一步教他在ECS上搭建Java+mysql+tomcat环境,所以把在这里把步骤在这简单整理了一下,以便需要的人查阅. 我购买的阿里云服务器系 ...

  5. MySQL集群PXC的搭建

    MySQL集群PXC的搭建 最近公司某客户要求我们的数据库搭建PXC集群以保证他们的系统高性能和搞稳定性 以后花费了一些时间去搭建和测试,也踩过一些坑,准备分享出来 系统:centos6.6PXC:5 ...

  6. Mysql 5.7 CentOS 7 安装MHA

    Table of Contents 1. MHA简介 1.1. 功能 1.2. MHA切换逻辑 1.3. 工具 2. 环境 2.1. 软件 2.2. 环境 3. Mysql 主从复制 3.1. Mys ...

  7. Linux+Apache+PHP+MySQL服务器环境(CentOS篇)

    1.前言 CentOS(Community ENTerprise Operating System)是Linux发行版之一,它是来自于Red Hat Enterprise Linux依照开放源代码规定 ...

  8. Linux下MySQL/MariaDB Galera集群搭建过程【转】

    MariaDB介绍 MariaDB是开源社区维护的一个MySQL分支,由MySQL的创始人Michael Widenius主导开发,采用GPL授权许可证. MariaDB的目的是完全兼容MySQL,包 ...

  9. MySQL优化之——集群搭建步骤具体解释

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46833179 1 概述 MySQL Cluster 是MySQL 适合于分布式计算 ...

  10. Mysql Innodb cluster集群搭建

    之前搭建过一个Mysql Ndb cluster集群,但是mysql版本是5.7的,看到官网上mysql8的还是开发者版本,所以尝试搭建下mysql Innodb cluster集群. MySQL的高 ...

随机推荐

  1. HOOK 底层键盘消息---WH_KEYBOARD_LL

    代码:屏蔽三个全局快捷键 代码的作用是屏蔽掉凝视中的三个快捷键. LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LP ...

  2. 在 Laravel 5.1 中使用 Pjax

    在 Laravel 5.* 的版本中,使用 Pjax 实现无刷新效果,以及酷炫的进度条 项目地址:https://github.com/yccphp/pjax-for-laravel-5 求 star ...

  3. android如何查看cpu的占用率和内存泄漏

    在分析内存优化的过程中,其中一个最重要的是我们如何查看cpu的占用率和内存的占用率呢,这在一定程度上很重要,经过查询资料,研究了一下,暂时了解到大概有以下几种方式,如果哪位高手有更好的办法,或者文中描 ...

  4. c++ ado 程序终止时崩溃

    在_ConnectionPtr析构的时候要将_ConnectionPtr置NULL ADODB::_ConnectionPtr conn;conn.CreateInstance(__uuidof(AD ...

  5. Librec的AoBPR算法实现

    Librec的AoBPR算法实现:(基于1.3版本) 要用AoBPR,但是没有找到相应的配置文件,应该怎么办呢?       ——因为用的是1.3版本,所以没有,2.0版本有的.[跟BPR参数一样,就 ...

  6. 说说JSON和JSONP,也许你会豁然开朗,含jQuery使用jsonp用例

    [原创]说说JSON和JSONP,也许你会豁然开朗,含jQuery用例  前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了 ...

  7. Linux命令-进程后台执行:nohup(就是不挂起的意思)

    nohup 就是不挂起的意思( no hang up) 用途:LINUX命令用法,不挂断地运行命令. 语法: nohup Command [ Arg ... ] [ & ] 描述:nohup ...

  8. windows10安装tensorflow的gpu版本(pip3安装方式)

    前言: TensorFlow 有cpu和 gpu两个版本:gpu版本需要英伟达CUDA 和 cuDNN 的支持,cpu版本不需要:本文主要安装gpu版本. 1.环境 gpu:确认你的显卡支持 CUDA ...

  9. Mac添加快捷键开启应用程序(转)

    最近使用终端比较多点,打开终端的方法有几种:比较常用有把终端添加到Dock栏上,然后就是利用Spotlight搜索Terminal来打开.但是两种方式还是让我感觉不太满意. 当开启的程序比较多的时候, ...

  10. 再说Android RecyclerView局部刷新那个坑

      RecyclerView局部刷新大家都遇到过,有时候还说会遇见图片闪烁的问题. 优化之前的效果: 优化之后的效果: 如果想单独更新一个item,我们通常会这样做,代码如下: mLRecyclerV ...