Linuxで新しいMySQLデータベースを作成して、文字セットの照合を指定し、sqlスクリプトを実行します
関連記事へのリンク:
CentOS6.8はMySQL8.0.17をインストールします
CentOS6.8はMySQL5.7.25をインストールします
CentOS6.8はMySQL5.7.25を完全にアンインストールします
表示する前のヒント:
この記事で使用されているLinuxバージョンはCentOSリリース6.10であり、mysqlバージョンは8.0.16です。
1.MySQLにログインします
インストールされたmysqlのbinディレクトリでコマンドを実行します
mysql -u user_name -p
システムにログインするためのパスワードを入力してください
2.データベースを作成します
注文の実行
create database db_name charset utf8 collate utf8_general_ci;
コーディング順序を表示
select * from information_schema.schemata where schema_name = 'db_name';
3.sqlスクリプトを実行します
sqlスクリプトは次のとおりです
データベースを選択
use db_name
注文の実行
source 路径/脚本.sql
表を見る
show tables;
補足
テーブルの文字セットを変更して並べ替えます
-- 修改数据库字符集和排序规则
alter database db_name character set utf8 collate utf8_general_ci;
-- 查看数据库的字符集
select * from information_schema.schemata where schema_name = 'db_name';
-- 修改表默认的字符集
alter table table_name character set gbk collate gbk_bin;
-- 修改表数据的字符集
alter table table_name convert to character set gbk collate gbk_bin;
-- 查看表的字符集
select * from information_schema.tables where table_schema = 'db_name' and table_name = 'table_name';
-- 修改字段的字符集
alter table table_name change column_name varchar(50) character set gbk collate gbk_bin;
-- 查看字段的字符集
select * from information_schema.columns where table_schema = 'db_name' and table_name = 'table_name';