Home > Database > Mysql Tutorial > body text

mysql配置

WBOY
Release: 2016-06-07 15:35:05
Original
990 people have browsed it

在Linux中安装好Mysql之后,要进行一些相关配置。 根据需要修改 /etc/my.cnf,参考配置: [mysqld] # 设置默认为 INNODB 表,支持事务,支持行锁: default-storage-engine=INNODB # 设置默认的字符集: default-character-set=utf8 # 客户机通信所使用的缓冲

在Linux中安装好Mysql之后,要进行一些相关配置。

根据需要修改 /etc/my.cnf,参考配置:
[mysqld]
# 设置默认为 INNODB 表,支持事务,支持行锁:
default-storage-engine=INNODB
# 设置默认的字符集:
default-character-set=utf8
# 客户机通信所使用的缓冲区大小的最大值
max_allowed_packet=16M

启动 MySQL:
service mysql start
/etc/init.d/mysql start
/usr/share/mysql/mysql.server start

[mysql.server]
# 注释掉 basedir 行,否则 MySql 可能不能启动
# 据说是 MySql 的 bug
# basedir=/var/lib

让MySQL系统启动时自动启动:
在 系统设置>服务器设置>服务 中把 MySql 打勾 
root登录时,自动启动mysql:
在 /root/.bash_profile 文件中增加1行:
/usr/share/mysql/mysql.server start

查看启动日志:
/var/log/messages

显示MySQL所有用户:
use mysql;
select host,user,password from user;

添加 MySQL 用户(user name:user1,password:sql):
grant all on *.* to user1@'%' identified by 'sql' with grant option;

删除 MySQL 用户:
delete from user where user='user1';

eg:我机器的配置
[client]
port                                            = 3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
default-character-set=utf8

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8

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

整理了以下四种在MySQL中修改root密码的方法,可能对大家有所帮助!

方法1: 用SET PASSWORD命令

  mysql -u root

  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

方法2:用mysqladmin

  mysqladmin -u root password "newpass"

  如果root已经设置过密码,采用如下方法

  mysqladmin -u root password oldpass "newpass"

方法3: 用UPDATE直接编辑user表

  mysql -u root

  mysql> use mysql;

  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

  mysql> FLUSH PRIVILEGES;

在丢失root密码的时候,可以这样

  mysqld_safe --skip-grant-tables&

  mysql -u root mysql

  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

  mysql> FLUSH PRIVILEGES;


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!