Mysql 安装 配置

Centos 升级MySQL版本或者Yum安装Mysql5.6


设置currenttime
http://www.metsky.com/archives/118.html
参考文件:
http://blog.csdn.net/shootyou/article/details/8236886

记得删除老版本的/etc/my.conf,/var/lib/mysql, 或者备份老版本的mysql
否则可能会起动不起来
http://www.th7.cn/db/mysql/201408/66691.shtml

修改用户密码:

update mysql.user set password=password("新密码") where User="root";

flush privileges;


// windows
修改登录密码 MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。  
1、命令  /usr/bin/mysqladmin -u root password 'new-password'**  
格式:
mysqladmin -u用户名 -p旧密码 password 新密码**  
2、例子  例1:给root加个密码123456。  
键入以下命令 :  
[root@test1 local]# /usr/bin/mysqladmin -u root password 123456

创建数据库:

 CREATE DATABASE `test2` DEFAULT  CHARACTER SET utf8 COLLATE utf8_general_ci;

修改my.cnf文件(mysql 减少内存使用)

# Example mysql config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld deamon
# doesn't use much resources.
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /var/lib/mysql) or
# ~/.my.cnf to set user-specific options.
#
# One can in this file use all long options that the program supports.
# If you want to know which options a program support, run the program
# with --help option.

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/run/mysqld/mysqld.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3306
socket = /var/run/mysqld/mysqld.sock
character-set-server=utf8

key_buffer = 16K
query_cache_limit = 256K
query_cache_size = 4M
max_allowed_packet = 1M

max_connections = 16
thread_concurrency = 2

sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K
performance_schema_max_table_instances=400

table_definition_cache=400

table_open_cache=256

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
#safe-updates

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout

# Uncomment the following if you want to log updates
#log-bin

# Uncomment the following if you are NOT using BDB tables
#skip-bdb

# Uncomment the following if you are using Innobase tables
#innodb_data_file_path = ibdata1:100M
#innodb_data_home_dir = /var/lib/mysql/
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
#set-variable = innodb_mirrored_log_groups=1
#set-variable = innodb_log_files_in_group=3
#set-variable = innodb_log_file_size=5M
#set-variable = innodb_log_buffer_size=8M
#innodb_flush_log_at_trx_commit=1
#innodb_log_archive=0
#set-variable = innodb_buffer_pool_size=16M
#set-variable = innodb_additional_mem_pool_size=2M
#set-variable = innodb_file_io_threads=4
#set-variable = innodb_lock_wait_timeout=50

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

字符编码

查看字符编码: status

1.关于MySQL字符集
MySQL的字符集支持(Character Set Support)有两个方面: 
 字符集(Character set)和排序方式(Collation)。
MySQL对于字符集的支持细化到四个层次: 服务器(server),数据库(database),数据表(table)和连接(connection)。
MySQL对于字符集的指定可以细化到一个数据库,一张表,一列,应该用什么字符集。
2.查看MySQL字符集
2.1.查看字符集的设置
mysql> show variables like 'character_set_%';

2.2.查看字符集排序设置
mysql> show variables like 'collation_%';

3.修改MySQL字符集
3.1修改服务器级别字符集
a.临时修改
mysql>SET GLOBAL character_set_server=utf8;
b.永久修改
 打开/etc/mysql/my.cnf,在[mysqld]后添加character-set-server=utf8
3.2修改数据库级 
a. 临时更改
mysql>SET GLOBAL character_set_database=utf8;
b. 永久更改
改了服务器级就可以了
3.3修改表级 
mysql>ALTER TABLE table_name DEFAULT CHARSET utf8; 更改了后永久生效
3.4修改列级修改示例
mysql>ALTER TABLE `products` CHANGE `products_model` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL; 更改了后永久生效 
3.5更改连接字符集
 a. 临时更改:mysql> SET GLOBAL character_set_client;
b. 永久更改:打开/etc/mysql/my.cnf,在[client]后添加default-character-set=utf8
Notice:3.1和3.5需要重启mysql:   service mysql restart

重起mysql

service mysqld restart

转:http://www.blogjava.net/nkjava/archive/2014/11/21/420406.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容