Linux(centos6.8)配置Mysql环境

时间:2022-04-20 12:49:26

1.下载mysql安装包

https://downloads.mysql.com/archives/community/

Linux(centos6.8)配置Mysql环境

2.查询mysql信息

[1]查询mysql是否已经安装

[root@pluto 桌面]# ps -ef|grep mysql

root       7921   6778  0 23:00 pts/3    00:00:00 grep mysql

[root@pluto 桌面]# rpm -qa|grep  mysql

mysql-libs-5.1.73-7.el6.x86_64

[root@pluto 桌面]# uname -a

Linux pluto.pluto 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

rpm包名基本格式:mysql-libs-5.1.73-7.el6.x86_64

|-名称:mysql-libs

|-版本号:5.1.73

|-适用操作系统:el6.x86_64,表示centos6.x的64位系统

通过以上的信息我们可以得知mysql已经安装了,所以我们只需要卸载就好了。安装我们想要的mysql版本。

[2]卸载原mysql

#普通删除模式

[root@pluto 桌面]# rpm -e mysql-libs

error: Failed dependencies:

libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64

libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64

mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64

#强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

[root@pluto 桌面]# rpm -e --nodeps mysql-libs

3.安装mysql

[1]安装mysql

[root@pluto opt]# rpm -ivh MySQL-server-5.5.48-1.linux2.6.i386.rpm

[root@pluto opt]# rpm -ivh MySQL-client-5.5.48-1.linux2.6.i386.rpm

注:如果出现error:libaio.so.1,则我们需要安装依赖包.目前我只会通过yum安装,要想通过yum安装必须保证linux是可以联网的。其它方式可以通过百度查询。

Linux(centos6.8)配置Mysql环境

[root@pluto opt]# rpm -ivh MySQL-server-5.5.48-1.linux2.6.i386.rpm

warning: MySQL-server-5.5.48-1.linux2.6.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

error: Failed dependencies:

libaio.so.1 is needed by MySQL-server-5.5.48-1.linux2.6.i386

libaio.so.1(LIBAIO_0.1) is needed by MySQL-server-5.5.48-1.linux2.6.i386

libaio.so.1(LIBAIO_0.4) is needed by MySQL-server-5.5.48-1.linux2.6.i386

#出现error:libaio.so.1则执行以下命令

[root@pluto opt]# yum install libaio.so.1

[root@pluto opt]# rpm -ivh MySQL-client-5.5.48-1.linux2.6.i386.rpm

warning: MySQL-client-5.5.48-1.linux2.6.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

error: Failed dependencies:

libncurses.so.5 is needed by MySQL-client-5.5.48-1.linux2.6.i386

#出现libncurses.so.5则执行以下命令

[root@pluto opt]# yum install libncurses.so.5

注:最好不要使用 yum install libaio这个命令,明确指出要安装的依赖包,否则有可能依然会提示依赖没有安装。

[2]查看mysql安装时创建的mysql用户和mysql组

[root@pluto 桌面]# cat /etc/passwd|grep mysql

mysql:x:496:493:MySQL server:/var/lib/mysql:/bin/bash

[root@pluto 桌面]# cat /etc/group|grep mysql

mysql:x:493:

或者通过以下方式可以查看是否安装成功,以下类似于java -version

[root@pluto 桌面]# mysqladmin --version

mysqladmin  Ver 8.42 Distrib 5.5.48, for Linux on i686

[3]启动|停止mysql

#启用mysql服务

[root@pluto 桌面]# service mysql start

Starting MySQL....                                         [确定]

#停止mysql服务

[root@pluto 桌面]# service mysql stop

Starting MySQL....                                         [确定]

4.配置MySql

[1]设置Mysql密码

[root@pluto 桌面]# /usr/bin/mysqladmin -u root password 123456

[2]设置mysql自启动

#将mysql加入自启动

[root@pluto 桌面]# chkconfig mysql on

[root@pluto 桌面]# chkconfig --list | grep mysql

mysql           0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

#查看runlevel

[root@pluto 桌面]# cat /etc/inittab

#查看开启启动的服务,带*表示为开机启动的服务

[root@pluto 桌面]# ntsysv

[3]mysql安装位置

[root@pluto 桌面]# ps -ef|grep mysql

root       8530      1  0 23:23 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/pluto.pluto.pid

mysql      8621   8530  0 23:23 pts/1    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/pluto.pluto.err --pid-file=/var/lib/mysql/pluto.pluto.pid

root       8750   8229  0 23:34 pts/1    00:00:00 grep mysql

[root@pluto 桌面]# cd /var/lib/mysql/

[root@pluto mysql]# ls -l

Linux(centos6.8)配置Mysql环境

[4]修改配置文件位置

[root@pluto mysql]# cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

Linux(centos6.8)配置Mysql环境

[5]修改mysql字符集

(1)查看mysql编码集

mysql> show variables like 'character%';

mysql> show variables like '%char%';

Linux(centos6.8)配置Mysql环境

默认的客户端和服务器都是用latin1,所以进行插入中文时会出现乱码

Linux(centos6.8)配置Mysql环境

(2)修改mysql编码集

[root@pluto etc]# vim /etc/my.cnf

[client]

#password       = your_password

port            = 3306

socket          = /var/lib/mysql/mysql.sock

default-character-set=utf8

[mysqld]

port            = 3306

character_set_server=utf8

character_set_client=utf8

collation-server=utf8_general_ci

socket          = /var/lib/mysql/mysql.sock

skip-external-locking

key_buffer_size = 384M

max_allowed_packet = 1M

table_open_cache = 512

sort_buffer_size = 2M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size = 32M

# Try number of CPU's*2 for thread_concurrency

thread_concurrency = 8

[mysql]

no-auto-rehash

default-character-set=utf8

[root@pluto etc]# service mysql restart

Shutting down MySQL.                                       [确定]

Starting MySQL..                                           [确定]

注:重新连接后重新create database并使用新建的库,然后新建的表才能插入、显示中文。

5.MySQL远程连接

https://www.cnblogs.com/happyhuangjinjin/p/8244851.html

[1].linux网络设置

[2].MySQL设置远程用户

在需要被远程的机器上添加可远程连接用户

https://zhidao.baidu.com/question/1771404477336032980.html

mysql> grant all privileges on *.* to root@'%' identified by '123456';

Linux(centos6.8)配置Mysql环境

[3].防火墙设置3306可通行

https://www.cnblogs.com/xxoome/p/6884376.html

[root@pluto 桌面]# vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

[root@pluto 桌面]# service iptables restart

Linux(centos6.8)配置Mysql环境