Linux安装MySQL教程

MySQL是非常常用的数据库相较于Oracle,其免费的的特性令人称道,是作为学习数据库入门的不二之选,另外安装软件我在/usr/local下安装,希望大家和我一起养成习惯。我演示在CentOS6.5中的安装教程:

MySQL下载

  • 对于下载,可以采用wget的方式下载,具体网址去官网找找,将地址复制
  • 可以采用win系统下载,用传输工具的方式例:WinSCP,传输到Linux系统上

  • 这是我的压缩包位置,大家可以随意放置

  • 这里写图片描述

MySQL解压

  • 将mysql解压到/home/local目录
 tar -zxvf /home/hadoop/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz -C /home/local
  • 将mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz更名为mysql
 mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql

建立用户和用户组

建立用户作为数据库的管理用户

  • 建立用户组 名字为dba
 groupadd -g 101 dba
  • 建立用户 名字为mysqladmin
 useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
  • 验证是否成功
[root@hadoop hadoop]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)

设置密码和copy环境变量

  • 设置密码
[root@hadoop local]# passwd mysqladmin
Changing password for user mysqladmin.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
  • 复制环境变量
 [root@hadoop local]# cp /etc/skel/.* /usr/local/mysql
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.gnome2'
cp: omitting directory `/etc/skel/.mozilla'

创建my.cnf文件

  • 在/etc/my.cnf文件中将下面代码覆盖
 [root@hadoop local]# vi /etc/my.cnf 

[client]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock

[mysqld]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock

skip-external-locking
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size= 32M
max_allowed_packet = 16M
myisam_sort_buffer_size=128M
tmp_table_size=32M

table_open_cache = 512
thread_cache_size = 8
wait_timeout = 86400
interactive_timeout = 86400
max_connections = 600

# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 32

#isolation level and default engine 
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED

server-id  = 1
basedir     = /usr/local/mysql
datadir     = /usr/local/mysql/data
pid-file     = /usr/local/mysql/data/hostname.pid

#open performance schema
log-warnings
sysdate-is-now

binlog_format = MIXED
log_bin_trust_function_creators=1
log-error  = /usr/local/mysql/data/hostname.err
log-bin=/usr/local/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file  = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err

#for replication slave
#log-slave-updates 
#sync_binlog = 1

#for innodb options 
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ibdata1:500M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/arch
innodb_log_files_in_group = 2
innodb_log_file_size = 200M

innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 50M
innodb_log_buffer_size = 16M

innodb_lock_wait_timeout = 100
#innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_locks_unsafe_for_binlog=1

#innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads=4
innodb-write-io-threads=4
innodb-io-capacity=200
#purge threads change default(0) to 1 for purge
innodb_purge_threads=1
innodb_use_native_aio=on

#case-sensitive file names and separate tablespace
innodb_file_per_table = 1
lower_case_table_names=1

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[mysqlhotcopy]
interactive-timeout

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

修改my.cnf的权限问题并切换用户

[root@hadoop local]# chown  mysqladmin:dba /etc/my.cnf 
[root@hadoop local]# chmod  640 /etc/my.cnf
[root@hadoop local]# ll /etc/my.cnf
-rw-r-----. 1 mysqladmin dba 2218 Dec  7 12:23 /etc/my.cnf
[root@hadoop ~]# chown -R mysqladmin:dba /usr/local/mysql
[root@hadoop ~]# chmod -R 755 /usr/local/mysql
[root@hadoop ~]# su - mysqladmin
[mysqladmin@hadoop ~]$ mkdir arch

第一次安装初始化

[mysqladmin@hadoop ~]$ scripts/mysql_install_db  --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Installing MySQL system tables...2017-12-07 17:34:13 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-12-07 17:34:13 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

Filling help tables...2017-12-07 17:34:42 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-12-07 17:34:42 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h hadoop password 'new-password'

Alternatively you can run:

  /usr/local/mysql/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.

You can start the MySQL daemon with:

  cd . ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

配置开机自启动

root@hadoop ~]# cd /usr/local/mysql
[root@hadoop mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
cp: overwrite `/etc/rc.d/init.d/mysql'? 
[root@hadoop mysql]# chmod +x /etc/rc.d/init.d/mysql
[root@hadoop mysql]# chkconfig --del mysql
[root@hadoop mysql]# chkconfig --add mysql
[root@hadoop mysql]# chkconfig --level 345 mysql on

启动MySQL

[mysqladmin@hadoop ~]$ rm -rf my.cnf 
[mysqladmin@hadoop ~]$ bin/mysqld_safe & 
[1] 2831
[mysqladmin@hadoop ~]$ 171207 17:40:27 mysqld_safe Logging to '/usr/local/mysql/data/hostname.err'.
171207 17:40:27 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[mysqladmin@hadoop ~]$ service mysql status
MySQL running (3474)                                       [  OK  ]

结束后,敲击回车

进入MySQL

[mysqladmin@hadoop ~]$ bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.05 sec)

大家加油!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值