linux安装配置mysql常见错误_Linux——MySQL安装、配置、常见的坑

安装前准备

下载地址

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

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

mysql-libs-5.1.73-3.el6_5.i686

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

通过 rpm -e 命令卸载。

[root@localhost ~]$ rpm -e mysql-libs-5.1.73-3.el6_5.i686

error: 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: NOKEY

Preparing... ########################################### [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_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly 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: NOKEY

Preparing... ########################################### [100%]

1:MySQL-client ########################################### [100%]

[root@localhost opt]#

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

[root@localhost opt]# cat /etc/passwd | grep mysql

mysql:x:496:493:MySQL server:/var/lib/mysql:/bin/bash

[root@localhost opt]#

[root@localhost opt]# cat /etc/group | grep mysql

mysql:x:493:

[root@localhost opt]#

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

[root@localhost opt]# mysqladmin --version

mysqladmin Ver 8.42 Distrib 5.5.48, for Linux on i686

[root@localhost opt]#

MySQL服务的启动、停止

启动

[root@localhost opt]# service mysql start

Starting MySQL.. [ OK ]

[root@localhost opt]# ps -ef|grep mysql

root 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.pid

mysql 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.pid

root 30125 29667 0 10:29 pts/0 00:00:00 grep mysql

[root@localhost opt]#

停止

[root@localhost opt]# service mysql stop

Shutting down MySQL. [ OK ]

[root@localhost opt]# ps -ef|grep mysql

root 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 mysql

mysql 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 -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

Server 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 its

affiliates. Other names may be trademarks of their respective

owners.

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中添加字符集配置

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

2、重新mysql服务

MySQL安装目录

[root@localhost mysql]# ps -ef |grep mysql

root 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.pid

mysql 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=3306

root 31099 30567 0 11:42 pts/2 00:00:00 grep mysql

[root@localhost mysql]#

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值