Mysql安装详解

本文详细介绍MySQL数据库从安装到配置的全过程,包括用户组与用户的创建、解压与链接安装包、权限设定、初始化脚本执行及服务启动等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.  首先添加mysql用户组

groupadd mysql  

shell> groupadd mysql


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

 useradd -g mysql mysql  

shell> useradd -g mysql mysql


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

 cd /usr/local   

 gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -  

shell> cd /usr/local

shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -


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

shell> ln -s full-path-to-mysql-VERSION-OS mysql   

shell> cd mysql  

shell> ln -s full-path-to-mysql-VERSION-OS mysql

shell> cd mysql


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

shell> chown -R mysql .  

shell> chown -R mysql .


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

shell> scripts/mysql_install_db --user=mysql  

shell> scripts/mysql_install_db --user=mysql


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

   chown -R mysql data  

shell> chown -R mysql data


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

bin/mysqld_safe --user=mysql &  

shell> bin/mysqld_safe --user=mysql &


9.
设置root密码

bin/mysqladmin -u root password '123123'  

shell> bin/mysqladmin -u root password '123123'


10.
登录mysql

 bin/mysql -u root -p   

Enter password:   

shell> bin/mysql -u root -p

Enter password:


登录成功会看到:

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>   

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> 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  

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> service mysql restart

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值