【linux】之安装mysql常用配置

下载mysql地址

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

选择下面这个

查看是否存在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

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

那么用以下方法

[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

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

myql目录迁移

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

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

chown -R mysql.mysql mysql

安装mysql5.7版本
 
http://blog.itpub.net/26506993/viewspace-1994769/
yum 安装mysql5.6

https://www.cnblogs.com/007sx/p/7083143.html
mysql5.7忘记密码

https://www.cnblogs.com/benjamin77/p/8681763.html

mysql5.7zip 安装

https://www.cnblogs.com/--net/p/6796445.html
原文地址:https://www.cnblogs.com/gyjx2016/p/5990664.html