linux下mysql安装和配置
⽹上的很多资料都有相关的⽂章,这⾥只是记录下⾃⼰安装过程中遇到的问题和解决⽅法:
linux内核版本:
~$ uname -a
Linux naci 3.19.0-16-generic #16-Ubuntu SMP Thu Apr 30 16:09:58 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
1.⾸先在liunx下安装Mysql数据库
~$ sudo apt-get install mysql-server #安装Mysql服务器端
~$ ps -aux|grep mysql #检查Mysql服务器进程
beili 10301 0.0 0.0 37080 3604 pts/7 S+ 5⽉20 0:00 mysql -u root -p
mysql 25125 0.0 0.0 4472 1704 ? Ss 09:51 0:00 /bin/sh /usr/bin/mysqld_safe
下载mysql服务端命令
mysql 25496 0.0 3.1 859956 127084 ? Sl 09:51 0:01 /usr/sbin/mysqd --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error= beili 26652 0.0 0.0 13708 2180 pts/19 S+ 10:32 0:00 grep --color=auto mysql
~$ netstat -nlt|grep 3306 #检查Mysql服务器占⽤端⼝
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
~$ /etc/init.d/mysql status # 通过启动命令检查Mysql服务器状态
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since 四 2015-05-21 09:51:13 CST; 43min ago
Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
~$ service mysql status # 通过系统服务检查Mysql服务器状态
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since 四 2015-05-21 09:51:13 CST; 44min ago
Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
~$ whereis mysql # 查看mysql各个⽂件安装的⽬录
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/
2.访问和配置Mysql
$ mysql -u root -p
Enter password:
mysql默认的字符集为latin1的,所以要改为utf8的。很多⽹上的⽂章执⾏“sudo vi /etc/mysql/myf”,可是打开⼀看,⾥⾯就两⾏
话:
!includedir /etc/mysql/conf.d/
!includedir /etc/f.d/
想来mysql的配置⽂件应该是在那两个⽂件夹下⾯,于是尝试之下打开了/etc/f.d/ 下的mysqldf⽂件,执⾏下⾯的
命令:
~$ sudo vi /etc/f.d/mysqldf ...
[client]
default-character-set=utf8
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
...
注:棕⾊部分是添加的内容
重启mysql服务,并查看字符集的设置情况:
~$ sudo /etc/init.d/mysql restart
~$ mysql -u root -p
mysql> show variables like "%char%"
+--------------------------+----------------------------+
| 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/ | +--------------------------+----------------------------+
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论