Home > Database > Mysql Tutorial > linux安装mysql.

linux安装mysql.

WBOY
Release: 2016-06-07 15:27:11
Original
1192 people have browsed it

下载地址: http://dev.mysql.com/downloads/mysql/ 1、添加用户组 # groupadd mysql 2、添加用户 # useradd -r -g mysql mysql 3、切换目录 # cd /usr/local 4、解压(mysql-5.5.22-linux2.6-i686.tar.gz已经复制到/usr/local下) # tar zxvf mysql-5.5.22-li

下载地址:
http://dev.mysql.com/downloads/mysql/


1、添加用户组
#> groupadd mysql
2、添加用户
#> useradd -r -g mysql mysql
3、切换目录
#> cd /usr/local
4、解压(mysql-5.5.22-linux2.6-i686.tar.gz已经复制到/usr/local下)
#> tar zxvf mysql-5.5.22-linux2.6-i686.tar.gz
5、创建软链接
#> ln -s mysql-5.5.22-linux2.6-i686 mysql
6、删除压缩包(可操作)
#> rm mysql-5.5.22-linux2.6-i686.tar.gz
7、进入mysql目录
#> cd mysql
8、改变用户权限和组权限
#> chown -R mysql .
#> chgrp -R mysql .

9、初始化数据库
保证在/etc/目录下面没有my.cnf、mysql文件夹,如果有请删除
安装libaio1.so 执行sudo apt-get install libaio1 安装了则跳过
#> scripts/mysql_install_db --user=mysql


初始化成功则出现如下提示:
Installing MySQL system tables...
OK
Filling help tables...
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:


./bin/mysqladmin -u root password 'root'
./bin/mysqladmin -u root -h VWmare password 'new-password'


Alternatively you can run:
./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 . ; ./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 with the ./bin/mysqlbug script!



10、修改权限
#> chown -R root .
#> chown -R mysql data



11、复制配置文件
#> cp support-files/my-medium.cnf /etc/my.cnf
#> cp support-files/mysql.server /etc/init.d/mysql.server



12、启动数据库
#> bin/mysqld_safe --user=mysql &


13、查看是否有3306端口启动
#> netstat -nat


14、设置密码
#> ./bin/mysqladmin -u root password 'new-password'
或者
#> ./bin/mysql_secure_installation


15、使用mysql
#> cd bin  
#> ./mysql -u root -p



16、设置开机自动启动
#> cd /etc/init.d/
sudo update-rc.d mysql.server defaults


17、设置默认编码为UTF8

登录MySQL,执行编码显示:

show variables like 'character%';

QUOTE:

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+


sudo vi /etc/mysql/my.cnf


找到[client] 添加:



default-character-set=utf8

找到[mysqld] 添加:


default-character-set=utf8

init_connect='SET NAMES utf8'


sudo/etc/init.d/mysql.server restart

修改好后,重新启动mysql 即可.


若启动异常则把[mysqld]处修改为

character_set_server = utf8

init_connect='SET NAMES utf8'


查询一下show variables like 'character%';

QUOTE:

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template