进入MySQL的安装目录,准备初始化
cd /usr/local/mysql
添加一个叫mysql的用户(自动创建mysql组),-s指定用户的默认Shell,-M取消家目录。
useradd -s /sbin/nologin -M
bin/mysql_install_db --user=mysql
初始化完成。
配置服务
cp share/mysql/mysql.server /etc/init.d/mysqld
mysqld就成为了系统中的一个服务
启动服务/etc/init.d/mysqld start,也可以用red hat的service命令service mysqld start
自启动
chkconfig mysqld on或者在/etc/rc[0-6].d/里面加软连接
bin/mysql
无法连接,报错
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
试一试
bin/mysql -h localhost
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
bin/mysql -h 127.0.0.1
这种利用的是TCP协议连接,可以连接上。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.72 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
根源问题在于/tmp/mysql.sock不存在。
配置mysql的配置文件,/etc/my.cnf
cp share/mysql/my-small.cnf /etc/my.cnf
再来一次mysql_install_db --user=mysql
启动服务
这样就能连接了。
修改密码
mysqladmin -uroot password 12qwas3434
把mysql里面的root用户密码改成12qwas3434
连接尝试
mysql -uroot -p12qwas3434 注意p 后面没空格。
润色my.cnf,改改字符集改成UTF-8
sed -i -e '/\[client\]/a\default-character-set=utf8' -e '/\[mysqld\]/a\default-character-set=utf8' /etc/my.cnf
【注】本指令可以优化吗?能优化请回复或者联系我哦。