您的位置:首页 > 运维架构 > Linux

Linux下安装与配置MySQL

2015-09-06 19:58 579 查看
在MySQL官网上下载MySQL安装包,系统是按照你当前系统类型来提供下载安装包。

MySQL官网:www.mysql.com

因为我的是Windows系统,所以只能下载Window的安装包。现需要下载一下Linux的安装包,弄来弄去还是无法在官网上下载。

可以通过MySQL官网提供Yum方式来安装,具体地址是:http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/index.html#repo-qg-yum-fresh-install

我的具体安装步骤如下(CentOS6.5 + MySQL5.6):

1. 下载rpm软件包

# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
2. 给文件加执行权限

# chmod u+x mysql-community-release-el6-5.noarch.rpm

3. 导入yum本地库

# yum localinstall -y mysql-community-release-el6-5.noarch.rpm

4. 查看是否有mysql软件信息,什么时候都可以查看一下

# yum list | grep mysql 或 yum repolist all | grep mysql

5. 安装MySQL,会连带client , devel一起安装

# yum install mysql-server 或 yum install mysql-community-server

6. 查看是否安装上了

# yum list installed | grep mysql

7. 启动和查看状态

# service mysqld start

# service mysqld status

8. 如果MySQL启动成功,使用应该命令时行首次设置root密码

# mysql_secure_installation

以下网上的yum安装方式,也可以实现,供参考:

从MySQL Yum仓库下载最新的rpm文件:http://dev.mysql.com/downloads/repo/yum/

CentOS 7 : http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-common-5.6.26-2.el7.x86_64.rpm
下载完成后将Yum库导入到你的本地

命令:# yum localinstall mysql-community-release-el7-5.noarch.rpm

安装前一些检查工作

查看有没有安装过:

# yum list installed mysql*

# rpm -qa | grep mysql*

查看有没有安装包:

# yum list | grep mysql*

用下面的命令来确认这个仓库被成功添加

# yum repolist enabled | grep "mysql.*-community.*

安装MySQL

# yum install mysql-community-server

# yum install mysql-devel

# yum install mysql-client

安装完毕,启动MySQL

# service mysqld start

# service mysqld status 验证是否启动成功

初次安装,设置root密码

# mysql_secure_installation

注:初始化的root密码为空,可通过上面命令进行首次root密码设置

一些其它的辅助命令

数据库字符集设置

mysql配置文件/etc/my.cnf中加入default-character-set=utf8

----------------------

vi /etc/my.cnf

#做如下配置

[client]

password = 123456

port = 3306

default-character-set=utf8

[mysqld]

port = 3306

character_set_server=utf8

character_set_client=utf8

collation-server=utf8_general_ci

#linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写

lower_case_table_names=1

#设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384

max_connections=1000

[mysql]

default-character-set = utf8

启动mysql服务

service mysqld start 或者 /etc/init.d/mysqld start

开机启动

chkconfig -add mysqld,查看开机启动设置是否成功chkconfig --list | grep mysql*

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

登录

# mysql -u root -p [password]

忘记密码

service mysqld stop

mysqld_safe --user=root --skip-grant-tables

mysql -u root

use mysql

update user set password=password("new_pass") where user="root";

flush privileges;

Linux MySQL的几个重要目录

数据库目录 /var/lib/mysql/

配置文件 /usr/share /mysql(mysql.server命令及配置文件)

相关命令 /usr/bin(mysqladmin mysqldump等命令)

启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录)

设置允许远程登录

mysql> use mysql;

mysql> select host,user,password from user;

mysql> update user set host='%' where user='root' and host='localhost';

mysql> flush privileges;

mysql> exit;

重置root密码

#设置root用户的密码

mysql> update user set password=password('123456') where user='root';

待续
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: