> 데이터 베이스 > MySQL 튜토리얼 > linux安装mysql.

linux安装mysql.

WBOY
풀어 주다: 2016-06-07 15:27:11
원래의
1205명이 탐색했습니다.

下载地址: 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/ |
+--------------------------+----------------------------+

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿