linux快速部署mysql服务器

1.首先添加mysql用户组

Shell代码 复制代码 收藏代码
  1. shell>groupaddmysql
shell> groupadd mysql


2.添加mysql用户,并指定到mysql用户组

Shell代码 复制代码 收藏代码
  1. shell>useradd-gmysqlmysql
shell> useradd -g mysql mysql


3.解压缩mysql-version.tar.gz到安装目录(/usr/local/)

Shell代码 复制代码 收藏代码
  1. shell>cd/usr/local
  2. shell>gunzip</path/to/mysql-VERSION-OS.tar.gz|tarxvf-
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -


4.为创建mysql软连接mysql-VERSION-OS

Shell代码 复制代码 收藏代码
  1. shell>ln-sfull-path-to-mysql-VERSION-OSmysql
  2. shell>cdmysql
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql


5.设定mysql安装目录权限,设置owner为mysql

Shell代码 复制代码 收藏代码
  1. shell>chown-Rmysql.
shell> chown -R mysql .


6.执行mysql系统数据库初始化脚本

Shell代码 复制代码 收藏代码
  1. shell>scripts/mysql_install_db--user=mysql
shell> scripts/mysql_install_db --user=mysql


7.设定data目录权限,分配给mysql用户,为了mysql程序能读写data目录下的文件

Shell代码 复制代码 收藏代码
  1. shell>chown-Rmysqldata
shell> chown -R mysql data


8.使用mysql帐号启动mysql应用

Shell代码 复制代码 收藏代码
  1. shell>bin/mysqld_safe--user=mysql&
shell> bin/mysqld_safe --user=mysql &


9.设置root密码

Shell代码 复制代码 收藏代码
  1. shell>bin/mysqladmin-urootpassword'123123'
shell> bin/mysqladmin -u root password '123123'


10.登录mysql

Shell代码 复制代码 收藏代码
  1. shell>bin/mysql-uroot-p
  2. Enterpassword:
shell> bin/mysql -u root -p
Enter password: 


登录成功会看到:

Shell代码 复制代码 收藏代码
  1. WelcometotheMySQLmonitor.Commandsendwith;or\g.
  2. YourMySQLconnectionidis229
  3. Serverversion:5.1.40-logMySQLCommunityServer(GPL)
  4. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.
  5. mysql>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 229
Server version: 5.1.40-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 



这时mysql已经装好了,可以查看数据库了,但在正式使用数据库开发与部署的时候还需要做一些工作:


1.设定配置文件my.cnf

按照需求copy my-***.cnf到/etc/my.cnf

2.修改默认字符集utf8

(1).[client]下加入default-character-set=utf8
(2).[mysqld]下加入default-character-set=utf8

3.设置默认存储引擎
mysql for linux的版本默认使用的数据库引擎是MyISAM,但只有InnoDB引擎支持事务,
所以需要修改配置:

(1).[mysqld]下加入default-storage-engine=INNODB

4.配置innodb参数


(1).找到# Uncomment the following if you are using InnoDB tables
去掉innodb_*下的所有#

(2).如果安装mysql的目录不是默认的,则需要修改
# mysql 默认安装目录为 /usr/local/mysql/
# mysql 默认表空间目录安装目录为 /usr/local/mysql/data/

innodb_data_home_dir=/usr/local/database/mysql/data/
innodb_log_group_home_dir=/usr/local/database/mysql/data/

5.设置系统服务

让linux启动的时候就启动mysql服务

Shell代码 复制代码 收藏代码
  1. shell>cd/usr/local/mysql/
  2. shell>cpsupport-files/mysql.server/etc/init.d/mysql
  3. shell>chmod777/etc/init.d/mysql
  4. shell>chkconfig--addmysql
  5. shell>chkconfig--level35mysqlon
shell> cd /usr/local/mysql/
shell> cp support-files/mysql.server /etc/init.d/mysql
shell> chmod 777 /etc/init.d/mysql 
shell> chkconfig --add mysql
shell> chkconfig --level 35 mysql on


6.重启MySQL服务

Shell代码 复制代码 收藏代码
  1. shell>service mysql restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值