CentOS是免费的、开源的、可以重新分发的开源操作系统,CentOS(Community Enterprise Operating System,中文意思是社区企业操作系统)是Linux发行版之一。
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。
本文将以centos6h和mysql5.7为基础,介绍linux系统下mysql的一系列安装与配置工作,为后续的学习和开发做准备。
一、mysql安装
1、在opt目录下准备好rpm安装包

2、检查当前系统是否安装过mysql
①、CentOS6 环境下
rpm -qa | grep -i mysql

默认 Linux 在安装的时候,自带了 mysql 相关的组件,先卸载系统自带的 mysql,执行卸载命令。
rpm -e --nodeps mysql-libs
①、CentOS7 环境下
rpm -qa | grep -i mariadb
默认 Linux(CentOS7)在安装的时候,自带了 mariadb(mysql 完全开源版本)相关的组件。 先卸载系统自带的 mariadb,执行卸载命令
rpm -e --nodeps
mariadb - libs
3、检查/tmp文件权限
-
查看/tmp文件夹权限**
/tmp文件夹权限
-
赋予其最大权限
赋予其最大权限
4、在安装目录下执行rpm安装
rpm -ivh MySQL-server-5.5.54-1.linux2.6.x86_64.rpm
rpm-ivh MySQL-client-5.5.54-1.linux2.6.x86_64.rpm

注:后面安装的不是这个版本,但是无伤大雅。如果差什么依赖直接yum install安装即可
5、查看是否安装成功
mysqladmin --version

也可以使用rpm命令来查看

二、 mysql的启动等操作
1、查看状态
service mysql status

2、启动服务
service mysql start

3、停止服务
service mysql stop

4、重启服务
service mysql restart

5、启动之后,查看进程
ps -ef | grep mysql

三、mysql安装位置及密码设置
1、mysql安装位置
2、修改mysql用户名和密码
mysqladmin -u root password xxxx

四、mysql自启动和数据库连接
1、mysql服务的自启动
mysql服务一开始就是开机自启的

如果不想开机自启,可以进入netsysv进行设定

使用空格取消选中,使用TAB确定
2、mysql连接数据库
五、mysql重复启动问题
1、问题
2、解决

六、mysql修改字符集
1、常用命令
2、未修改字符集时的中文乱码问题
3、字符集乱码原因
如果在建库建表的时候,没有明确指定字符集,则采用默认的字符集 latin1,其中是不包含中文字符的。查看默认的编码字符集
4、配置文件备份
注意!这是在mysql5.5版本,若是更新的版本就不一定叫这个了

备份完后记得重启服务

5、通过配置文件永久修改字符集

在需要的地方添加内容
6、重启mysql服务

7、再次查看字符集编码
注意:已经创建的数据库的设定不会发生变化,参数修改只对新建的数据库有效!!!!
8、在新创建的数据库中测试中文是否能正常使用

显然正常
9、处理已创建的表和库
修改数据库的字符集
mysql>alter database mydb character set 'utf8';
修改数据表的字符集
mysql>alter table mytbl convert to character set 'utf8';
10、处理已经乱码的数据
无论时修改mysql配置文件或是修改库、表的字符集,都无法改变已经变成乱码的数据,只能删除数据重新插入或者更新数据才可以解决。
七、mysql授权外部连接
1、授权外部访问


网友评论