Mysql 安裝 配置

weixin_34146805發表於2015-09-24

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

相關文章