linux下安装mysql以及乱码解决

inux下安装mysql以及乱码解决

#修改用户环境变量
cd 回车  到用户的默认路径
ll -a
vi .bash_profile
#在export PATH后面增加
export LANG="zh_CN.gbk"
#生效
source .bash_profile


#拷贝安装文件 拷贝一个文件到一个目录下
cp  /appcom/appcom/install_media/mysql-5.5.11-linux2.6-x86_64.tar.gz  /appcom/com/

#进入到拷贝目录 解压文件
cd /appcom/com/
tar zxvf mysql-5.5.11-linux2.6-x86_64.tar.gz

#删除压缩文件
rm mysql-5.5.11-linux2.6-x86_64.tar.gz

#为了方便重命名文件
mv mysql-5.5.11-linux2.6-x86_64  mysql

#到mysql目录下 执行安装命令
scripts/mysql_install_db --user=appcom  --basedir=/appcom/com/mysql --datadir=/appcom/com/mysql/data
    
#修改配置文件           
cd mysql/support-files/
vi mysql.server
指定下面两项:
在这段代码下面
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/appcom/com/mysql
datadir=/appcom/com/mysql/data

#mysql下面如果没有my.cnf 拷贝一份
cp ../support-files/my-medium.cnf
#重命名
mv my-medium.cnf my.cnf

#修改my.cnf在
[client]下添加
character_set_server=utf8
[mysqld]下添加
character_set_server=utf8



#启动
到mysql下的support目录下
./mysql.server  start
#停止
./mysql.server  stop


#到达bin目录 登录mysql u帐户 h主机 P端口号
./mysql -uroot -h 127.0.0.1 -P 3306

#到mysql的命令行下面 设置数据库字符集为utf8
set names utf8;
charset utf8;

#查看字符编码命令
mysql> show variables like 'character_set%';
+--------------------------+-----------------------------------+
| Variable_name            | Value                             |
+--------------------------+-----------------------------------+
| character_set_client     | gbk                               |
| character_set_connection | gbk                               |
| character_set_database   | utf8                              |
| character_set_filesystem | binary                            |
| character_set_results    | gbk                               |
| character_set_server     | utf8                              |
| character_set_system     | utf8                              |
| character_sets_dir       | /appcom/com/mysql/share/charsets/ |
+--------------------------+-----------------------------------+
8 rows in set (0.00 sec)


mysql> show variables like 'collation_%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | gbk_chinese_ci  |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)



#在mysql命令行下执行sql文件 sql的文件保存为utf-8格式  sql文件的路径
source /appcom/appcom/update/pahome1.0.0.0/sql/createTables.sql  
source /appcom/appcom/update/pahome1.0.0.0/sql/initData.sql  
source /appcom/appcom/update/pahome1.0.0.0/sql/rollback.sql

 


#创建用户并赋权限
grant all privileges on *.* to pahome@'%' identified by 'pahome' with grant option;
flush privileges

你可能感兴趣的:(sql,mysql,linux,SQL Server,bash)