下载mysql地址

 http://dev.mysql.com/downloads/mysql/

选择下面这个

 

【linux】之安装mysql常用配置_html

 

查看是否存在mysql安装包

rpm -qa|grep -i mysql

删除mysql安装包 --nodeps 忽略依赖关系
rpm -e --nodeps mysql-libs-5.1.61-4.el6.i686

安装mysql服务端
rpm -ivh MySQL-server-5.5.50-1.el6.i686.rpm

安装mysql客户端
rpm -ivh MySQL-client-5.5.50-1.el6.i686.rpm

--------------------------------------------------------
配置mysql初始密码
mysqladmin -uroot password root

mysqladmin -u root -p password 1234

如果以上配置出现一下错误

【linux】之安装mysql常用配置_MySQL_02

那么用以下方法

[root@localhost mysql]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';

mysql> FLUSH PRIVILEGES;

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

mysql
登录进去之后更改密码
set password=password('123');

加入到系统服务列表
chkconfig --add mysql

自动启动
chkconfig mysql on

查看自动启动列表
chkconfig

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

记住在mysql5.5之后 是mysqld

 

登录mysql

例如,你想root使用root密码 从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'root' WITH GRANT OPTION;

如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY

'mypassword' WITH GRANT OPTION;

 

需要刷新一下才能生效
FLUSH PRIVILEGES

 

切换到外部

开放3306端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
保存防火墙规则
/etc/rc.d/init.d/iptables save
刷新防火墙规则
service iptables save
service iptables restart
以上两个都行

查看端口开放情况

/etc/init.d/iptables status 

service iptables status

ls | grep mysql 文件搜索

linux查看字符集编码

show variables like 'character_set_%';

/etc/下在my.cnf或my.ini下找到[mysqld], 在其下方添加一行:

character_set_server=utf8

更改client编码

[client]
default-character-set= utf8

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

 在rpm 安装的mysql可能在/etc 目录下面没有 my.cnf 文件,

需要自己拷贝/usr/share/mysql 下的 my-default.cnf   到/etc下并且命名问my.cnf

需要先ps -ef|grep mysql,看一下相关启动文件在哪里,以下是示例文件

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
lower_case_table_names = 1
basedir=/usr
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/localhost.localdomain.pid
user=mysql
port=3306
character_set_server=utf8
innodb_buffer_pool_size = 128M
query_cache_type=1
query_cache_size=32M
[mysqld_safe]
log-error=/var/lib/mysql/localhost.localdomain.err
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.

 以上配置在centos6.3下,我将所有需要的依赖已经全部安装,如果出现相关错误,请安装相应的依赖lib文件

 

myql目录迁移

【linux】之安装mysql常用配置_MySQL_03

如上,将/opt下数据库迁移到/var/lib下面,重启

【linux】之安装mysql常用配置_mysql_04

查看日志发现需要重新授权

【linux】之安装mysql常用配置_mysql_05

chown -R mysql.mysql mysql

 

安装mysql5.7版本
 
http://blog.itpub.net/26506993/viewspace-1994769/
  • 1.
  • 2.
  • 3.

 

yum 安装mysql5.6
  • 1.

 

mysql5.7忘记密码


mysql5.7zip 安装

  • 1.
  • 2.
  • 3.
  • 4.