Linux——MySQL安装、配置

来源:互联网 发布:做广告的软件 编辑:程序博客网 时间:2024/06/08 02:27

安装前准备

下载地址

mysql官网地址:https://dev.mysql.com/downloads/mysql/#downloads

检查当前系统是否安装过MySQL

[root@localhost opt]# rpm -qa|grep -i mysqlmysql-libs-5.1.73-3.el6_5.i686

执行上面命令发现系统自带了一个mysql-libs包,需要卸载之。
通过 rpm -e 命令卸载。

[root@localhost ~]$ rpm -e mysql-libs-5.1.73-3.el6_5.i686error: Failed dependencies:        libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64        libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64        mysql-libs is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64

由于存在依赖卸载失败,解决办法:–nodeps 强力删除模式:

rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.i686

在删除完以后我们可以通过 rpm -qa | grep mysql 命令来查看mysql是否已经卸载成功!!

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

安装MySQL服务端(注意提示:设置root密码)

[root@localhost 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: NOKEYPreparing...                ########################################### [100%]   1:MySQL-server           ########################################### [100%]170424 10:17:19 [Note] /usr/sbin/mysqld (mysqld 5.5.48) starting as process 29889 ...170424 10:17:19 [Note] /usr/sbin/mysqld (mysqld 5.5.48) starting as process 29897 ...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_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.Please report any problems at http://bugs.mysql.com/[root@localhost opt]# 

安装MySQL客户端

[root@localhost 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: NOKEYPreparing...                ########################################### [100%]   1:MySQL-client           ########################################### [100%][root@localhost opt]# 

查看MySQL安装时创建的mysql用户和mysql组

[root@localhost opt]# cat /etc/passwd | grep mysqlmysql:x:496:493:MySQL server:/var/lib/mysql:/bin/bash[root@localhost opt]# 
[root@localhost opt]# cat /etc/group | grep mysqlmysql:x:493:[root@localhost opt]# 

或者执行如下命名查看mysql安装版本信息:

[root@localhost opt]# mysqladmin --versionmysqladmin  Ver 8.42 Distrib 5.5.48, for Linux on i686[root@localhost opt]# 

MySQL服务的启动、停止

启动

[root@localhost opt]# service mysql startStarting MySQL..                                           [  OK  ][root@localhost opt]# ps -ef|grep mysqlroot     30007     1  0 10:29 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pidmysql    30100 30007  4 10:29 pts/0    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/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pidroot     30125 29667  0 10:29 pts/0    00:00:00 grep mysql[root@localhost opt]# 

停止

[root@localhost opt]# service mysql stopShutting down MySQL.                                       [  OK  ][root@localhost opt]# ps -ef|grep mysqlroot     30163 29667  0 10:31 pts/0    00:00:00 grep mysql[root@localhost opt]# 

设置root密码

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

也可以登录mysql进行修改:

[root@localhost opt]# mysql -uroot -p......mysql>use mysql;mysql> update user set password=passworD("123456") where user='root';mysql> flush privileges;mysql> exit;  

自启动MySQL服务

设置MySQL服务器在运行级别2、3、4、5上自启动运行(on),其他级别上默认为off

[root@localhost opt]# chkconfig mysql on //相当于chkconfig --level 2345 mysql on[root@localhost opt]# chkconfig --list|grep mysqlmysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off[root@localhost opt]# 

补充:如果执行chkconfig –list|grep mysql 命名没有发现mysql服务,需要自己到mysql安装目录下拷贝一份启动脚本到开机启动也就是/etc/init.d/目录下,操作如下:

[root@localhost opt]#cp /usr/share/mysql/mysql.server /etc/init.d/mysql[root@localhost opt]#chmod 755 /etc/init.d/mysql[root@localhost opt]#chkconfig --add mysql [root@localhost opt]#chkconfig mysql on [root@localhost opt]#service mysql restart

修改MySQL配置文件位置

拷贝配置文件到/etc目录下
mysql5.5版本:

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

mysql5.6版本:

[root@localhost init.d]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf[root@localhost init.d]# 

解决中文存储乱码问题

查看

[root@localhost ~]# cls[root@localhost ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.5.48 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show variables like '%char%';+--------------------------+----------------------------+| Variable_name            | Value                      |+--------------------------+----------------------------+| character_set_client     | utf8                       || character_set_connection | utf8                       || character_set_database   | latin1                     || character_set_filesystem | binary                     || character_set_results    | utf8                       || character_set_server     | latin1                     || character_set_system     | utf8                       || character_sets_dir       | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.00 sec)mysql> 

默认客户端和服务器都是用了latin1,所有中文存储会乱码

解决办法

1、/etc/my.cnf中添加字符集配置
这里写图片描述
这里写图片描述
2、重新mysql服务

MySQL安装目录

[root@localhost mysql]# ps -ef |grep mysqlroot     30708     1  0 11:34 pts/2    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pidmysql    31021 30708  0 11:34 pts/2    00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock --port=3306root     31099 30567  0 11:42 pts/2    00:00:00 grep mysql[root@localhost mysql]# 

这里写图片描述

2 0
原创粉丝点击